Author Topic: Tracking perl hack script in server style golfreeze  (Read 10787 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Tracking perl hack script in server style golfreeze
« on: มกราคม 23, 2011, 12:26:45 AM »
#พอดี เครื่องที่ได้ดูแล มีปัญหาเรื่อง perl script น่ะครับ ลักษณะคือมีการรัน perl5.7 อยู่ซึ่งเป็น
user apache สำหรับวิธีการ tracking หาต้นตอ นั้น ขอให้มีสติ ให้นิ่งก่อน แล้วเริ่มใช้วิธีง่ายๆ ดังนี้
ครับ
1.find command

#find / -user apache -name "*.pl"
#find / -user apache -name "*.txt"

ดูเจอไฟล์ไหนแปลกๆ ก็เข้าไปดูครับ

2.จะเข้าไปดูตาม log ของ access กับ error_log ใน apache ครับ
#less /var/log/httpd/access_log
#less /var/log/httpd/error_log

3.เข้าไปใน ไฟล์พวก log ของ ไฟล์ ftp log
#less /var/log/xferlog

4.อีกวิธีที่ผมชอบใช้ คือ ใช้ตัว application มาช่วย คือตัว lsof

ตัวนี้ เก๋าพอสมควร ซึ่งมันจะ หา ip ที่ connection "ESTABLISH" อยู่

และบางทีอาจปรากฏเป็น path ที่รันไฟล์อยู่ด้วย เราก็เข้าไปจัดการได้เลย

#lsof -i -n -P | more
ถ้าเจอ ip ที่เชื่อมต่อก็ block เพื่อตัดปัญหาที่ปลายทางไปก่อนก็ได้ครับ

5.ลองดู crontab ของ user นั้นๆเช่น
#crontab -u apache -l
ถ้าเจอ ก็ตามไปดู ไฟล์นั้น

6.ทำการ ตรวจไวรัสโดยใช้ tools clamscan ช่วย
#clamscan /

ึ7.ถ้าไม่เจอ จริงๆ แล้วล่ะก็ทำการ Killall process นั้นทิ้งซะ เช่น
#killall -9 perl5.7.8


ซึ่งปัญหาที่เกิดขึ้น แอดมินแต่ล่ะคนก็ แก้ปัญหาตามสไตส์ที่ตนเองถนัด สำหรับผมก็จะใช้ประมาณนี้
เลยอยากมาแชร์ให้เพื่อนๆ ได้ทราบ เผื่ออาจจะช่วยท่านได้บ้าง

แต่สุดท้าย ทุกอย่างก็ล้วนไม่มีอะไรสมบูรณ์ มันเป็น อนิจจัง ครับ

golfreeze[at]packetlove.com

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Tracking perl hack script in server style golfreeze
« Reply #1 on: มกราคม 23, 2011, 12:26:53 AM »
ddos command

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
route add 12.219.178.143 reject
route add 202.173.147.138 reject

===============

netstat -a | grep SYN | wc -l
iptables -A INPUT -s 124.177.148.139 -j DROP
#List ip ไหนว่ามี connection กี่ครั้งเข้ามาที่ server
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Tracking perl hack script in server style golfreeze
« Reply #2 on: มกราคม 23, 2011, 12:27:08 AM »
First aid for DDOS attack on port 80

First aid for DDOS attack on port 80

We can use the following steps to recover our server from a DDOS attack on the port 80. To do this
you must have logged into the server as a root user.



Step 1 : Install/Configure APF firewall
=============================

a) If there are no firewalls installed on the server please install the same,
you will get the steps and directions from the following site.

http://www.webhostgear.com/61.html


b) Turn on the antidos option (USE_AD) in the APF conf file

# vi /etc/apf/conf.apf

USE_AD = 1




Step 2 : Install/Configure mod_evasive (for Apache 1.3x)
=============================


mod_evasive and mod_dosevasive are the same

a) Install mod_evasive

# wgethttp://www.zdziarski.com/projects/mo..._1.10.1.tar.gz
# tar -xzvf mod_evasive_1.10.1.tar.gz
# cd mod_evasive

# /usr/local/apache/bin/apxs -i -a -c mod_evasive.c
# /etc/init.d/httpd restart


b) Also include the following lines in the apache conf file

# vi /usr/local/apache/conf/httpd.conf

-------------------------------------------------

DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10

-------------------------------------------------


c) Restart the webserver

# /etc/init.d/httpd restart





Step 3 : Install mod_security
=============================



Normally we can find/install this module from WHM
WHM >> cPanel >> Addon Modules >> Select "modsecurity "
>>save






Step 4 : Blocking IPs

a) Find the IPs those have established a connection with the server

(The following command is the better one to get the IPs, as this will sort the IPs
according to the number of connections).


netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n


b) Block them using IPTABLES

# iptables -I INPUT -s 218.92.207.28 -j DROP
# service iptables save
# service iptables restart


c) Block them on APF too

# vi /etc/apf/deny_hosts.rules


# service apf restart




Step 5 : Optimizing the httpd.conf file
=============================


# vi /usr/local/apache/conf/httpd.conf

Change the bellow options as follows, original values are shown in the
bracket.

MaxKeepAliveRequests 50 (100)
KeepAliveTimeout 60 (30)


Also edit the following options too, according to the situation.

Timeout
KeepAliv
MinSpareServers
MaxSpareServers
MaxClients




Step 6 : Install/Configure 3rd party DDOS prevention tools
=============================

We can also use the most trusting 3rd party script 'DDoS-Deflate' for preventing DDOS attack
effectively.
Steps to install this script are as follows.

# wgethttp://www.inetbase.com/scripts/ddos/install.sh
# sh install.sh

Add the script '/usr/local/ddos/ddos.sh' to cron as follows

# crontab -e

*/5 * * * * /usr/local/ddos/ddos.sh >/dev/null 2>&1





Step 7 : Suspend websites
=============================

Check the bandwidth usage of all the domains and suspend the high bandwidth consuming domains for a
while





PERMANENT WAY TO FIX THE DDOS ATTACK
=============================

As we all know the softwares have its own limitations for preventing against DDOS attack, we can
follow these steps to cure it permanently.

1. Ask the NOC for attaching Cisco Guard on the server for 24 hours
(Normally this service is free from most NOCs)

2. Attach a hardware firewall for the server



Hope this will help you in such a situation, for more information kindly refer the following URL:
http://forums.cpanel.net/showthread.php?t=66952

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Tracking perl hack script in server style golfreeze
« Reply #3 on: มกราคม 23, 2011, 12:27:43 AM »
บางครั้ง เราอาจจะใช้วิธีหา ข้อความที่เป็นคำสั่งใน file ของ user ได้
คือผมเคยมี case หนึ่งซึ่งหาด้วยวิธีอื่นไม่เจอจริงๆ เลยใช้วิํธี หาโดย

#cd /folder/problem

#ใช้คำสั่ง ค้นหา
#find . -iname '*.*' -print | xargs grep -il 'mail'

และสามารถเช๊ค connection ได้คือ
netstat -anp | grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

เช๊คดูการทำงานของ disk , utilization
#iostat -x 2

เช๊คดูการทำงานของ การเขียน อ่าน disk
#iotop

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Tracking perl hack script in server style golfreeze
« Reply #4 on: พฤษภาคม 09, 2016, 12:45:09 PM »
## cut last column in text file by awk  '{print $NF}'

06/04   NEW HAMPSHIRE INSURANCE CBANGKOK TH     07/04   367.00
06/04   ESSO-VPK CHAROENNAKORN(1)BANGKOK TH     08/04   600.00
07/04   BTS BANGKOK TH  08/04   450.00
09/04   SHABU HAVEN-C.PLAZA PINKLBANGKOK TH     09/04   998.00
13/04   40.00 U.S. DOLLAR ********* CONVERTED GB     14/04   1,439.39
15/04   0.99 U.S. DOLLAR ********* CONVERTED LU    16/04   35.70
15/04   2C2P *LIONAIR BANGKOK TH        16/04   1,400.00
19/04   True iService BANGKOK TH        20/04   1,485.16
20/04   ESSO-VPK CHAROENNAKORN(1)BANGKOK TH     22/04   800.00
20/04   2C2P *LIONAIR BANGKOK TH        22/04   1,200.00
21/04   571,019.00 RUPIAH ********* CONVERTED TOPT Trinusa Travelindo JAKARTA ID        23/04   1,560.85
23/04   IT CITY -L.PINKLAO 3 FL BANGKOK TH      23/04   439.00
23/04   PTTRM_CB BANBUNG 2 CHONBURI TH  23/04   500.00
26/04   ESSO-VPK CHAROENNAKORN(1)BANGKOK TH     27/04   500.00
30/04   True iService BANGKOK TH        01/05   1,427.25
01/05   ESSO-VPK CHAROENNAKORN(1)BANGKOK TH     03/05   500.00
02/05   2C2P *LIONAIR BANGKOK TH        03/05   1,100.00
03/05   TOPS PRANNOK BANGKOK TH 03/05   358.00
04/05   THE MALL 5 THONBURI DEPT.BANGKOK TH     05/05   291.00


#less text.txt |  awk  '{ print $NF}'
367.00
600.00
450.00
998.00
1,439.39
35.70
1,400.00
1,485.16
800.00
1,200.00
1,560.85
439.00
500.00
500.00
1,427.25
500.00
1,100.00
358.00
291.00

ถ้าต้องการ sum ค่าที่ออกมาทั้งหมด ก็เป็นดังนี้ ครับ
#less text.txt |  awk  '{ print $NF}' | sed 's/,//g' | bc | cut -d. -f1 | paste -sd+ | bc
« Last Edit: พฤษภาคม 16, 2016, 03:05:14 PM by golfreeze »