找回密码
 入住遨海湾
搜索
网站解决方案专享优惠-3折上云
查看: 1023|回复: 0

查出Linux下网站哪些文件被挂马的办法

[复制链接]
发表于 2019-9-17 08:05:03 | 显示全部楼层 |阅读模式

登录后查才能浏览下载更多咨询,有问题联系QQ:3283999

您需要 登录 才可以下载或查看,没有账号?入住遨海湾

×
php后门木马常用的函数大致上可分为四种类型:
7 W# f7 U9 G- k+ }4 Q
  1. 1. 执行系统命令: system, passthru, shell_exec, exec, popen, proc_open
    - }% z! Q) ~" l9 J' u- k
  2. 2. 代码执行与加密: eval, assert, call_user_func,base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13
    2 M; [6 r& ~$ M8 v( t. o
  3. 3. 文件包含与生成: require, require_once, include, include_once, file_get_contents, file_put_contents, fputs, fwrite
    8 r6 \3 F& ?3 o0 ?
  4. 4. .htaccess: SetHandler, auto_prepend_file, auto_append_file
复制代码
二  想找一个 关键词是“hellow word” 在哪些文件中有,我们用grep命令/ x: ?" J( q" s, `; Y7 @' D2 G
  1. grep –color -i -r -n “hellow word”  /data/www/
复制代码
" J+ i% E3 M3 G# z+ \/ i" W
这样就能搜索出来 文件中包含关键词的文件
1 |5 w. c4 s) ]–color是关键词标红( O; ^: c" [: u  t* F. `6 \
-i是不区分大小写! [  n. k' y2 q* a4 `
-r是包含子目录的搜索, e7 J* `& e1 A% L
-d skip忽略子目录
. q. d+ W7 I9 _, [) n  H' L可以用以上命令查找网站项目里的带有挂马的文件" u9 z) {% Q9 `( ~

) v6 }5 v) \! g7 J( h; j三 .两个查后门的实用linux命令:
2 S0 d8 F/ c3 h4 P7 d  n3 H0 K
  1. find /data/web/website/ -iname *.php -mtime -35 找出/data/web/website/目录下 35分钟前新建的php' r2 m" Y4 J  q  o/ j& c
  2. find /data/web/website/ -name “*.php” | xargs grep “eval($_POST[” 找出/data/web/website/ 里面源码包含eval($_POST[的php文件
复制代码

9 N0 X$ @: L# R- O四  例如  注入漏洞eval(base64_decode" [  E2 t6 i' O7 N1 t& {
  1. grep –color -i -r -n “eval”  /data/www/   找出来对比以前正常的代码,看是否正常。然后用stat查看这个木马文件的修改时间,最后去寻找WEB日志,找
复制代码
出木马从哪里进来的
4 X! K. G$ y$ P0 }五:实用查找PHP木马命令:9 a" X( X; n+ h: ]; y8 f
查找PHP木马
* g: E$ I4 T+ z& n
  1. # find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc"> /tmp/php.txt
    ) ]/ v5 ?# D8 Q& [" u: q
  2. # grep -r --include=*.php  '[^a-z]eval($_POST' . > /tmp/eval.txt( v5 d* N9 |3 o# e) g& B7 l
  3. # grep -r --include=*.php  'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt) i& t; f1 B. s0 Q8 B# c
  4. # find ./ -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq3 f! W  B/ p. N3 x/ L' |
  5. & \+ Q- p8 F5 [. d8 `( m& t
  6. # find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc"> /tmp/php.txt
    $ S1 A4 S% m* I. c5 Y
  7. # grep -r --include=*.php  '[^a-z]eval($_POST' . > /tmp/eval.txt
    - ?+ c  r$ S- n% g
  8. # grep -r --include=*.php  'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt
    ) |4 d4 l; `$ {. Y, ~# p8 R
  9. # find ./ -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq
复制代码
查找最近一天被修改的PHP文件
; e, Y* K3 a# Q. z: u/ J
  1. #   find -mtime -1 -type f -name \*.php
    8 v' W1 c! \; ]- `+ M
  2. #   find -mtime -1 -type f -name \*.php
复制代码
修改网站的权限
% g3 v1 a2 i' ?/ y
  1. # find -type f -name \*.php -exec chmod 444 {} \;
    9 _5 l' u% t* w! G# [& h4 f
  2. # find ./ -type d -exec chmod 555{} \;
    * M  G) O1 t* s5 w1 t
  3. # find -type f -name \*.php -exec chmod 444 {} \;  h  [% x; [- _' z
  4. # find ./ -type d -exec chmod 555{} \;
复制代码
假设最后更新是10天前我们可以查找10天内生成的可以php文件:! [1 G0 q7 h5 C# [5 T/ T
  1. find /var/www/ -name “*.php” -mtime -10
复制代码
也可以通过关键字的形式查找 常见的木马常用代码函数 eval,shell_exec,passthru,popen,system
; A. H+ h- y3 e0 o8 y) l
  1. #find /var/www/ -name “*.php” |xargs grep “eval” |more( a1 k4 f  q7 B0 b0 L0 Q
  2. #find /var/www/ -name “*.php” |xargs grep “shell_exec” |more
    / g* n0 C  j( J7 f$ }  o+ ^
  3. #find /var/www/ -name “*.php” |xargs grep “passthru” |more
    6 S# {7 k0 {. y' ]; l
  4. #find /var/www/ -name “*.php” |xargs grep “eval” |more
    : d% P) b, l' Z2 k6 x7 [0 V  _9 @
  5. #find /var/www/ -name “*.php” |xargs grep “shell_exec” |more( |2 |5 j/ K1 d/ ?& N
  6. #find /var/www/ -name “*.php” |xargs grep “passthru” |more
复制代码
还有查看access.log 当然前提是你网站的所有php文件不是很多的情况下
+ i% K& e9 O2 }一句话查找PHP木马  _8 [4 Q8 j* h9 b2 Z1 I
  1. # find ./ -name “*.php” |xargs egrep “phpspy|c99sh|milw0rm|eval(gunerpress|eval(base64_decode|spider_bc”> /tmp/php.txt
    2 _% o2 D5 [" P1 L; C1 G
  2. # grep -r –include=*.php ’[^a-z]eval($_POST’ . > /tmp/eval.txt: v# d7 A' D4 t# d8 v/ ~
  3. # grep -r –include=*.php ’file_put_contents(.*$_POST[.*]);’ . > /tmp/file_put_contents.txt
    ) ^6 W5 g3 Q# F8 n8 u9 `, f0 x" W. o8 I
  4. # find ./ -name “*.php” -type f -print0 | xargs -0 egrep “(phpspy|c99sh|milw0rm|eval(gzuncompress(base64_decode|eval(base64_decode|spider_bc|gzinflate)” | awk -F: ‘{print $1}’ | sort | uniq
    * Z5 U3 G! F1 J- M1 B
  5. # find ./ -name “*.php” |xargs egrep “phpspy|c99sh|milw0rm|eval(gunerpress|eval(base64_decode|spider_bc”> /tmp/php.txt
    ; F( \: n, r7 D/ y
  6. # grep -r –include=*.php ’[^a-z]eval($_POST’ . > /tmp/eval.txt
      c- U9 ~  e3 x/ y, e5 Y
  7. # grep -r –include=*.php ’file_put_contents(.*$_POST[.*]);’ . > /tmp/file_put_contents.txt
    8 B- R4 }2 }4 c# e* M% x
  8. # find ./ -name “*.php” -type f -print0 | xargs -0 egrep “(phpspy|c99sh|milw0rm|eval(gzuncompress(base64_decode|eval(base64_decode|spider_bc|gzinflate)” | awk -F: ‘{print $1}’ | sort | uniq
复制代码

4 W1 ]7 G, @. }- K查找最近一天被修改的PHP文件. o" y& C2 ~: T% ?- F  _
  1. # find -mtime -1 -type f -name *.php
复制代码
4 p, G; T: r9 x. _1 r7 T/ L
六 以下其实是多余的操作了其实,但是还是有值得看的地方- W+ b4 \( W# q! X  R
7 ^  t! J. t8 I. D. J+ G3 S& R
检查代码。5 Z8 i) b( o' |8 v

8 Q9 _/ C, l# w; D0 |肯定不是一个文件一个文件的检查,Linxu有强悍的命令4 b* I, `' R+ Y% f9 n
grep ‘eval’ * -R 全盘搜索当前目录所有文件(包含子目录)中带有eval的文件,这条可以快速查找到被挂马的文件。
4 d+ F$ d  U2 ]$ s. G关于eval,请自行google一句话php代码。
  p, u% a& M1 R# k; o; ]% K
" |# c" ^$ z; l( A" [7 X; X3 P; u2,查看日志。
! q; w% S, q3 ^" i( a  {% s% S* S不到这个时候不知道日志的可贵啊。
5 t8 E, l1 ?5 `; m还是以grep命令为主。
# o6 }" N& F: i; U思路:负责的站点是Linux,只开了2个端口,一个22和80,外部的执行命令是由从80端口进来,Selinux报httpd访问/boot文件,确认被挂马。而所有的命令执行必须POST提交给执行的文件。所以,查找日志中所有的POST记录。
; C" s8 C0 S1 r) p0 F' ocat access_log_20120823.log | grep ‘POST’ | grep -v ‘反向查找’ | less,通过grep -v排除正常post,egrep也支持正则,但是太复杂了,看懂不知道怎么运用。! i: ]# D' G$ |. ]: U& J

9 b, p6 I: w/ m3 J(这里不建议用cat,用tail可以追加一个文件来看)
5 c) P) c3 ~3 B9 v1 m! F$ Z$ |8 ]- M5 m0 [  `* y
这可以防患于未然,防止不知道哪天又被人黑进来了。每天看一眼日志。
6 F- `4 _/ ^1 i0 d1 T) D/ E" a" `3 i! S2 q0 i% v: g* D
3,对于网页目录,只给apache用户rx权限,不要给w权限,目录设置要加上rx,不要给w,个别文件除外。所以,配合2使用,Linux下可以快速过滤刷选出来不规则的POST请求。+ a( K7 o  S/ S
综合1,2其实就可以快速查找被黑的页面,被修改的文件替换干净的代码。( N) A5 G) r! l) M
9 @; p: n6 y2 b( r, N2 _# U' {

5 E# x4 Y: B8 g) O6 u( ]2 O- |' I) U" ~1 b
遨海湾-心灵的港湾 www.aosea.com
您需要登录后才可以回帖 登录 | 入住遨海湾

本版积分规则

网站解决方案专享优惠-3折上云

QQ|手机版|小黑屋|遨海湾超级社区

GMT+8, 2025-5-15 08:05

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表