1/25/2018

[METASPLOIT] alias plugin을 이용하여 resource script를 명령어로 만들기

msf관련해서 어제 밤에 테스트하다가 어이없게 알아낸.. alias 플러그인데 대한 이야기를 할까 합니다. (설마설마 했는데, 있었네요 =_=)

alias plugin?

많이 익숙한 이름입니다. 별칭으로 생각하시면 좋아요. 미리 긴 명령행과 옵션을 하나의 명령어처럼 별칭으로 지정해두고 사용합니다. 대표적으로 bash에서 bashrc나 bash_profile에 alias로 명령행 정의해두고 사용하죠.

바로 이 기능이... 플러그인으로 있습니다. alias 플러그인입니다.

먼저 alias 플러그인을 로드합니다.

HAHWUL> load alias

help를 보면.. 아주 단순한데(초기화 정도 옵션..) bash에서 쓰는 alias와 동일합니다. = 대신 metasploit 룰대로 공백으로 인자값 넘겨주면 인식합니다.

HAHWUL> help alias
Usage: alias [options] [name [value]]


OPTIONS:

    -c <opt>  Clear an alias (* to clear all).
    -f <opt>  Force an alias assignment.
    -h        Help banner.


여러가지 작업이나 타이핑하기 힘든 데이터를 alias로 정의해서 사용하면 편리합니다.
아래와 같이 단축어로 바꿀수도 있구요.

HAHWUL> alias s search
HAHWUL> 
HAHWUL> s jenkins

Matching Modules
================

   Name                                                  Disclosure Date  Rank       Description
   ----                                                  ---------------  ----       -----------
   auxiliary/gather/jenkins_cred_recovery                                 normal     Jenkins Domain Credential Recovery
   auxiliary/scanner/http/jenkins_command                                 normal     Jenkins-CI Unauthenticated Script-Console Scanner
   auxiliary/scanner/http/jenkins_enum   

Make command!

그럼 몇가지 트릭을 써서 명령어를 만들어봅시다. 직접 msf코드를 수정하는 것보다 에러날 확률도 적고 업데이트로 망가지지도 않습니다.

우선 mad-metasploit에 rc 파일 하나 올려뒀는데, 코드 복붙이 귀찮으시면 git에서 받으셔도 됩니다.

https://github.com/hahwul/mad-metasploit/tree/master/resource-script


예전에 hosts 명령 손볼떄 잠깐 썼던 코드인데, 오늘 예제로 사용하겠습니다. 기존 hosts 명령보다 좀 더 많은 정보를 주는.. 그런 스크립트에요.

ahosts.rc
(http://www.hahwul.com/2017/09/metasploit-customize-column-and-tagging.html 참고)

<ruby>

rtype = Array.new(4)
rtype[0] = "'name,address,state,service_count,os_name,mac,os_sp,tags'"
rtype[1] = "'name,address,os_name,mac,tags,virtual_host'"
rtype[2] = "'name,address,service_count,vuln_count,cred_count,host_detail_count'"
rtype[3] = "'address,arch,comm,comments,created_at,cred_count,detected_arch,exploit_attempt_count,host_detail_count,info,mac,name,note_count,os_family,os_flavor,os_lang,os_name,os_sp,purpose,scope,service_count,state,updated_at,virtual_host,vuln_count,tags'"

puts " - [0] #{rtype[0]}"
puts " - [1] #{rtype[1]}"
puts " - [2] #{rtype[2]}"
puts " - [3] #{rtype[3]}"

print_status "Input type"
typ = gets.chomp

case typ
when "0"
   self.run_single("hosts -c "+rtype[0])
when "1"
   self.run_single("hosts -c "+rtype[1])
when "2"
   self.run_single("hosts -c "+rtype[2])
when "3"
   self.run_single("hosts -c "+rtype[3])
else
   print_error "Wrong choice"
end
</ruby>

msfconsole에서 alias로 ahosts 라는 이름으로 resource script를 불러줍니다.

HAHWUL> alias ahosts 'resource ~path~/mad-metasploit/resource-script/ahosts.rc'


그럼 마치 명령어처럼 사용이 가능하죠.


Init script에 포함하여 자동 로딩

예전에... init script 관련해서 포스팅한적이 있습니다. 자세한건 아래 링크 보시는게 좋을 것 같습니다.

요약하자면, msfconsole을 실행할 떄 인자값으로 바로 실행할 resource script를 지정할 수 있는데  여기에 alias 플러그인을 로드하고 미리 지정해두면 자동으로 명령어가 로딩될겁니다.

custom.rc
(http://www.hahwul.com/2017/07/metasploit-make-custom-msfconsole-with.html 참고)

setg Prompt "SHELL(Sessions: %S Jobs: %J)"
load alias
alias ahosts 'resource ~path~/mad-metasploit/resource-script/ahosts.rc'
clear

대충 세팅은 했고..  실행해보면

#> ./msfconsole -r custom.rc

매우 간단!

Reference

http://www.hahwul.com/2017/09/metasploit-customize-column-and-tagging.html
http://www.hahwul.com/2017/07/metasploit-make-custom-msfconsole-with.html






HAHWUL

Security engineer, Gopher and H4cker!

Share: | Coffee Me:

0 개의 댓글:

Post a Comment