分页: 5/19 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]
Apr 29
1.站点根目录下查找是否被放置webshell木马根据语句判断是不是PHP木马脚本

# find ./ -name “*.php” |xargs egrep “phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decode|spider_bc”>/tmp/php.txt

# grep -r –include=*.php  ‘[^a-z]eval_r($_POST’  > /tmp/eval.txt

#grep -r –include=*.php  ‘file_put_contents(.*$_POST\[.*\]);’ > tmp/file_put_contents.txt

2.统计服务器访问日志中所有不同ip出现的次数

# cat access.log |awk ‘{print $4}’| sort | uniq -c |sort -rn

或者

#cat access.log  | awk ‘{print $4}’ | sort -n | awk ‘{S[$NF]++} END {for(a in S) {print a”\t” S[a]}}’ | sort +1 -2nr

awk ‘{print $4}’ :  通过管道将第四个字段也就是ip地址筛选出来。

sort -n :将ip地址进行排序

awk ‘{S[$NF]++} END{for(a in S) {print a”\t” S[a]}}:

$NF是awk里的一个变量,代表最后一个字段的内容,由于这晨只有一个字段,即:IP地址,所以$NF代表IP地址。

S[$NF]++里的S代表一个数组,然后统计IP地址出现的次数. 后面是一个for in 循环语句,将这个数组里的值和键打印出来。

sort +1 -2nr:以第二个字段,也就是每个IP的访问次数进行排序

3.分析出现次数最多的ip对网站的具体数据访问情况

# grep -e IP access.log > filename

# cat filename |awk ‘{print $8}’|sort|uniq -c|sort -rn

4.访问次数最多的文件或页面,取前20

# cat access.log|awk ‘{print $11}’|sort|uniq -c|sort -nr|head -20

5.列出传输最大的几个exe文件(分析下载站的时候常用)

# cat access.log |awk ‘($7~/\.exe/){print $10 ” ” $1 ” ” $4 ” ” $7}’|sort -nr|head -20

6.列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数

# cat access.log |awk ‘($10 > 200000 && $7~/\.exe/){print $7}’|sort -n|uniq -c|sort -nr|head -100

7.如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面

# cat access.log |awk ‘($7~/\.php/){print $NF ” ” $1 ” ” $4 ” ” $7}’|sort -nr|head -100

8.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数

# cat access.log |awk ‘($NF > 60 && $7~/\.php/){print $7}’|sort -n|uniq -c|sort -nr|head -100

9.列出传输时间超过 30 秒的文件

# cat access.log |awk ‘($NF > 30){print $7}’|sort -n|uniq -c|sort -nr|head -20

10.统计网站流量(G)

# cat access.log |awk ‘{sum+=$10} END {print sum/1024/1024/1024}’

11.统计404的连接

# awk ‘($9 ~/404/)’ access.log | awk ‘{print $9,$7}’ | sort

12. 统计http status.

# cat access.log |awk ‘{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'

# cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn

13.查找挂马内容进行批量清除

# find /webbase/ -type f -exec grep 'www.800816.com.cn' -l {} \;

# sed -i "s/body{.*www.800816.com.cn.*}//g" `grep www.800816.com.cn -rl ./`

14.批量转换GBK为UTF-8文件编码

# find default -type d -exec mkdir -p utf/{} \;

# find default -type f -exec iconv -f GBK -t UTF-8 {} -o utf/{} \;

15.find查找文件的时候怎么避开多个文件目录

# find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "*.txt" -print

16.查看tcp的并发请求数及其TCP连接状态:

# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

# netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn

# netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'

# netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'

# netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn

# netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

17.查找请求数前20的IP(常用于查找攻来源)

# netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20

# netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n10

18.查看有多少个活动的php-cgi进程

# netstat -anp | grep php-cgi | grep ^tcp | wc -l

19.查找较多time_wait连接

# netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

20.找查较多的SYN连接

# netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

21.根据端口列进程

# netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1

22.抓包用来防止80端口被人攻击时可以分析数据

# tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts

23.用tcpdump嗅探80端口的访问看看谁最高

# tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

24.查看是哪些蜘蛛在抓取内容。

# /usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'


25.按域统计流量

# zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%s\t%d\n",domain,trfc[domain]}}'

26.查看数据库执行的sql

# /usr/sbin/tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'

27.将匹配Root一行中no替换成yes

# sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config

28.去掉第一列

# awk '{for(i=2;i<=NF;i++) if(i!=NF){printf $i" "}else{print $i} }' list

29.按内存从大到小排列

# ps -e -o "%C : %p : %z : %a"|sort -k5 -nr

30.按cpu利用率从大到小排列

# ps -e -o "%C : %p : %z : %a"|sort -nr

31.怎样知道某个进程在哪个CPU上运行

# ps -eo pid,args,psr

32.清除僵死进程。

# ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9

33.查看硬件制造商

# dmidecode -s system-product-name

34.查找占用磁盘IO最多的进程

# wget -c http://linux.web.psi.ch/dist/scientific/5/gfa/all/dstat-0.6.7-1.rf.noarch.rpm

# dstat -M topio -d -M topbio

35.检查I/O使用率(%util)是否超过100%

# iostat -x 1 2

36.磁盘空间,检查是否有分区使用率(Use%)过高(比如超过90%) 如发现某个分区空间接近用尽,可以进入该分区的挂载点,用以下命令找出占用空间最多的文件或目录:

# df -h

# du -cks * | sort -rn | head -n 10

37.CPU负载检查前三个输出值是否超过了系统逻辑CPU的4倍。

# cat /proc/loadavg

38.CPU的数量

# cat /proc/cpuinfo |grep -c processor

39.检查网络流量(rxbyt/s, txbyt/s)是否过高

# sar -n DEV

40.每隔1秒显示一下网络流量

# watch -n 1 "/sbin/ifconfig eth0 | grep bytes"

41.批量覆盖目录下的文件不用确定是否执行

# \cp -rf /svn/wwwroot /wwwroot

42.调试命令

# strace -p pid

43.跟踪指定进程的PID

# gdb -p pid

44.查看当前进程打开了多少个文件句柄

lsof -n |awk ‘{print $2}’|sort|uniq -c |sort -nr|more

45.查找最近一天被修改的HTML文件

find -mtime -1 -type f -name \*.html

46.修改网站的权限

find -type f -name \*.php -exec chmod 444 {} \;

find ./ -type d -exec chmod 555{} \;
Apr 29
查找一句话PHP木马:
# find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decode|spider_bc"> /tmp/php.txt

# grep -r --include=*.php  '[^a-z]eval($_POST' . > /tmp/eval.txt

# grep -r --include=*.php  'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt

# 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

查找最近一天被修改的PHP文件:
#   find -mtime -1 -type f -name \*.php

修改网站的权限:
# find -type f -name \*.php -exec chmod 444 {} \;

# find ./ -type d -exec chmod 555{} \;

建议将php相关危险函数在php.ini里面禁用掉。
disable_functions = system,exec,shell_exec,passthru
Tags: , ,
Apr 29
语句写法:
  find 对应目录 -mtime +天数 -name “文件名” -exec rm -rf {} \;
  例1:
  find /usr/local/backups -mtime +10 -name “*.*” -exec rm -rf {} \;
  将/usr/local/backups目录下所有10天前带”.”的文件删除
  find:Linux的查找命令,用户查找指定条件的文件
  /usr/local/backups:想要进行清理的任意目录
  -mtime:标准语句写法
  +10:查找10天前的文件,这里用数字代表天数,+30表示查找30天前的文件
  ”*.*”:希望查找的数据类型,”*.jpg”表示查找扩展名为jpg的所有文件,”*”表示查找所有文件,这个可以灵活运用,举一反三
  -exec:固定写法
  rm -rf:强制删除文件,包括目录
  {} \; :固定写法,一对大括号+空格+\+;
  若嫌每次手动执行语句太麻烦,可以将这小语句写到一个可执行文件中,再设置cron调度执行,那就可以让系统自动去清理相关文件。
例2:
  1.#touch /usr/local/bin/clear
  #chmod 777 clear
  新建一个可执行文件clear
  2.vi clear
  编辑clear文件如下:
  #!/bin/sh
  find /usr/local/backups -mtime +10 -name “*.*” -exec rm -rf {} \;
  ok,保存退出
  3.#crontab -e
  将clear文件加入到系统计划任务,到点自动执行
  输入:
  * 2 * * */usr/local/bin/clear
  这里的设置是每天凌晨2点执行clear文件进行数据清理,可以研究一下cron,制定自己需要的计划任务
  示例:
  #!/bin/sh
  find /usr/local/jboss-4.2.3.GA/server/default/log -mtime +6 -name “server.log.*” -exec rm -rf {} \;
  exit
  [root@web3 ~]# crontab -l
  * 2 * * * sh /root/AutoDelLog.sh
  这样每天晚上2点执行这个脚本,脚本是删除6天前的文件
扩展:
find /etc/rc.d -name ‘*crond’ -exec file {} \;
  查找/etc/rc.d目录下面所有以crond结束的文件,并使用file指令查看其属性,注意:exec和file间是一个空格,file和{}间是一个空格,{}和\;之间是一个空格,\;是一个整体。
Apr 20
Environment


SUSE Linux Enterprise Desktop 11
SUSE Linux Enterprise Desktop 10
SUSE Linux Enterprise Server 11
SUSE Linux Enterprise Server 10

Situation


An NFS client is successfully mounting an NFS v4 file system.  However, upon executing "ls -al," all the file user and group ownership is showing as "nobody" or as "4294967294", instead of the values that are shown when viewed directly on the remote NFS server.

Resolution


For user names to be displayed correctly, the NFS v4 server must have knowledge of the same user and group accounts as the NFS client.  If users and groups are centrally managed, this works automatically.  With previous NFS protocol versions, it was sufficient to create identical user accounts on all clients accessing an NFS server. These accounts didn't need to exist on the server itself because the files were only served by user ID.  However, with NFSv4, identity tracking has been redesigned and now uses a identity mapping daemon (idmapd).  It's crucial that server and client have access to identical account information, or idmapd cannot properly do it's job and may display ownership as "nobody" or equivalent high values.

Both the NFS server and the NFS client must run idmapd and have good idmapd.conf files.  Even when the same accounts are known to both the servers and clients, idmapd configuration problems can prevent proper ownership from being displayed.

Check the /etc/idmapd.conf file.  The [General] section should have a Domain setting.  This typically matches the DNS domain name, but does not necessarily have to.  NFS servers and NFS clients which interact with each other should have their idmap domains set identically.  It can also be helpful for there to be a [Translation] section which specifies the method of translating between names and IDs.  Typically, it is best to point to nsswitch methodology.
  
So, for example, a typical idmapd.conf file might look like the following:

[General]
Verbosity=7
Pipefs-Directory=/var/lib/nfs/rpc_pipefs
Domain=test.novell2.com
  
[Mapping]
Nobody-User=nobody
Nobody-Group=nobody
  
[Translation]
Method=nsswitch

If changes are made to this file on any system, or if a system is already configured this way and still does not function correctly, try restarting idmapd.  On some versions of SLES (typically SLE 10) this can be done with:
rcidmapd restart

On other versions (typically SLE 11), idmapd isn't setup to stop and start independently of NFS services, so the necessary commands would be:

If the system is an nfs client:
rcnfs restart

If the system is an NFS server:
rcnfsserver restart

If the system is both an NFS server and an NFS client:
rcnfs stop
rcnfsserver stop
(repeat the above commands if messages indicate something could not be stopped or is busy)
rcnfsserver start
rcnfs start

Disclaimer


This Support Knowledgebase provides a valuable tool for NetIQ/Novell/SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
Mar 30
在执行某个命令的时候,有时需要依赖于前一个命令是否执行成功。例如,假设你希望将一个目录中的文件全部拷贝到另外一个目录中后,然后删除源目录中的全部文件。在删除之前,你希望能够确信拷贝成功,否则就有可能丢失所有的文件。
在本章中,我们将讨论:

命令执行控制。
命令组合。

如果希望在成功地执行一个命令之后再执行另一个命令,或者在一个命令失败后再执行另一个命令,&&和||可以完成这样的功能。相应的命令可以是系统命令或shell脚本。
Shell还提供了在当前shell或子shell中执行一组命令的方法,即使用()和{}。

6.1 使用&&

使用&&的一般形式为:
命令1 && 命令2
这种命令执行方式相当地直接。&&左边的命令(命令1)返回真(即返回0,成功被执行)后,&&右边的命令(命令2)才能够被执行;换句话说,“如果这个命令执行成功&&那么执行这个命令”。
这里有一个使用&&的简单例子:
$ cp justing.doc justing.bak && echo “if you are seeing this then cp was OK”
if you are seeing this then cp was OK
在上面的例子中,&&前面的拷贝命令执行成功,所以&&后面的命令(echo命令)被执行。
再看一个更为实用的例子:
$ mv /apps/bin /apps/dev/bin && rm -r /apps/bin
在上面的例子中,/apps/bin目录将会被移到/apps/dev/bin目录下,如果它没有被成功执行,就不会删除/apps/bin目录。
在下面的例子中,文件quarter_end.txt首先将被排序并输出到文件quarter.sorted中,只有这一命令执行成功之后,文件quarter.sorted才会被打印出来:
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted

6.2 使用||

使用||的一般形式为:
命令1 || 命令2
||的作用有一些不同。如果||左边的命令(命令1)未执行成功,那么就执行||右边的命令(命令2);或者换句话说,“如果这个命令执行失败了|| 那么就执行这个命令”。
这里有一个使用||的简单例子:
$ cp wopper.txt wopper.bak || echo “if you are seeing this cp failed”

cp: wopper.txt: No such file or directory
if you are seeing this cp failed
在上面的例子中,拷贝命令没有能够被成功执行,因此||后面的命令被执行。
这里有一个更为实用的例子。我希望从一个审计文件中抽取第1个和第5个域,并将其输出到一个临时文件中,如果这一操作未成功,我希望能够收到一个相应邮件:
$ awk ‘{print $5}’ acc.qtr > qtr.tmp || echo “Sorry the payroll extraction didn’t work” | mail dave
在这里不只可以使用系统命令;这里我们首先对month_end.txt文件执行了一个名为comet的shell脚本,如果该脚本未执行成功,该shell将结束。
$ comet month_end.txt || exit

6.3 用()和{}将命令结合在一起

如果希望把几个命令合在一起执行, shell提供了两种方法。既可以在当前shell也可以在子shell中执行一组命令。
为了在当前shell中执行一组命令,可以用命令分隔符隔开每一个命令,并把所有的命令用圆括号()括起来。
它的一般形式为:
(命令1;命令2;. . .)
如果使用{ }来代替(),那么相应的命令将在子shell而不是当前shell中作为一个整体被执行,只有在{ }中所有命令的输出作为一个整体被重定向时,其中的命令才被放到子shell中执行,否则在当前shell执行。它的一般形式为:
{命令1;命令2;. . . }
我很少单独使用这两种方法。我一般只和&&或||一起使用这两种方法。
再回到前面那个comet脚本的例子,如果这个脚本执行失败了,我很可能会希望执行两个以上的命令,而不只是一个命令。我可以使用这两种方法。这是原先那个例子:
$ comet month_end.txt || exit
现在如果该脚本执行失败了,我希望先给自己发个邮件,然后再退出,可以用下面的方法来实现:
$ comet month_end || (echo “Hello, guess what! Comet did not work”|mail dave;exit)
在上面的例子中,如果只使用了命令分隔符而没有把它们组合在一起,shell将直接执行最后一个命令(exit)。
我们再回头来看看前面那个使用&&排序的例子,下面是原来的那个例子:
$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted
使用命令组合的方法,如果sort命令执行成功了,可以先将输出文件拷贝到一个日志区,然后再打印。

6.4 小结

在编写shell脚本时,使用&&和||对构造判断语句非常有用。如果希望在前一个命令执行失败的情况不执行后面的命令,那么本章所讲述的方法非常简单有效。使用这样的方法,可以根据&&或||前面命令的返回值来控制其后面命令的执行。
分页: 5/19 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]