|
发表于 2006-2-6 01:13:09
|
显示全部楼层
通过用 IDA 对 init 静态反编译发现,里面做了好多细微工作,包括释放一些文件(猜测),但调用的时候却是远程调用一些库
由于 BBIagent 用的是 uclibc,而非普通的 glibc,所以 IDA 没能跟踪出函数名称,只知道调用参数,所以换了另外的方法
通过对 rootfs 展开后,将里面 init 用到的 lib 库复制到 Linux 系统中后,用 ltrace 跟踪 init 发现了一些线索
[root@PT_LINUX sbin]# ltrace init
__libc_start_main(0x804cb40, 1, 0xbffffb24, 0x804d178, 0x804d1c0
strrchr("init", '/') = NULL
umask(022) = 022
geteuid() = 0
getpid() = 20509
getopt(1, 0xbffffb24, "t:") = -1
fprintf(0x40150e00, "Usage: %s 0123456SsQqAaBbCcUu\n", "init"Usage: init 0123456SsQqAaBbCcUu
) = 32
exit(1
+++ exited (status 1) +++
[root@PT_LINUX sbin]# ltrace ./init
__uClibc_start_main(1, 0xbffffb24, 0xbffffb2c, 0x8049300, 0x8055128
malloc(1024) = 0x8058f48
malloc(1024) = 0x8059350
malloc(128) = 0x8059758
__xpg_basename(0xbffffc18, 0xbffffafc, 0x400008c6, 0x40005248, 2704) = 0xbffffc1a
openlog("init", 1, 176) =
strcmp("init", "connect") = 1
strcmp("init", "sconf") = -1
strcmp("init", "init") = 0
signal(15, 0x804cd28) = NULL
umask(022) = 022
mkdir("/proc", 0555) = -1
mount(0x80564d2, 0x80564cc, 0x80564cd, 0, 0) = -1
mount(0x80564d2, 0x80564de, 0x80564d7, 0, 0) = -1
mkdir("/tmp", 01777) = -1
symlink("/proc/mounts", "/etc/mtab") = -1
mkdir("/tmp/var", 0755) = -1
symlink("/tmp/var", "/var") = -1
mkdir("/var/run", 0755) = -1
mkdir("/var/log", 0755) = -1
mkdir("/var/conf/", 0600) = -1
mkdir("/bin", 0755) = -1
mkdir("/usr", 0755) = -1
symlink("/", "/usr/local") = -1
symlink("/bin", "/usr/bin") = -1
memcpy(0xbffff8c0, "_]\005\bg]\005\br]\005\b~]\005\b\211]\005\b\225]\005\b\236]\005\b\250]\005\b"..., 92) = 0xbffff8c0
symlink("/sbin/ifconfig", "/bin/sh") = -1
symlink("/sbin/ifconfig", "/bin/route") = -1
symlink("/sbin/ifconfig", "/bin/insmod") = -1
symlink("/sbin/ifconfig", "/bin/rmmod") = -1
symlink("/sbin/ifconfig", "/bin/gunzip") = -1
symlink("/sbin/ifconfig", "/bin/tar") = -1
symlink("/sbin/ifconfig", "/bin/true") = -1
symlink("/sbin/ifconfig", "/bin/cat") = -1
symlink("/sbin/ifconfig", "/bin/false") = -1
symlink("/sbin/ifconfig", "/bin/gunzip") = -1
symlink("/sbin/ifconfig", "/bin/gzip") = -1
symlink("/sbin/ifconfig", "/bin/kill") = -1
symlink("/sbin/ifconfig", "/bin/killall") = -1
symlink("/sbin/ifconfig", "/bin/mkdir") = -1
symlink("/sbin/ifconfig", "/bin/rm") = -1
symlink("/sbin/ifconfig", "/bin/tar") = -1
symlink("/sbin/ifconfig", "/bin/test") = -1
symlink("/sbin/ifconfig", "/bin/unzip") = -1
symlink("/sbin/ifconfig", "/bin/yes") = -1
symlink("/sbin/ifconfig", "/sbin/klogd") = -1
symlink("/sbin/ifconfig", "/sbin/logread") = -1
symlink("/sbin/ifconfig", "/sbin/syslogd") = -1
fopen("/proc/cmdline", "r") = 0x80597e0
memset(0xbffff880, '\000', 128) = 0xbffff880
fgets("ro root=LABEL=/ acpi=force conso"..., 128, 0x80597e0) = 0xbffff880
strstr("ro root=LABEL=/ acpi=force conso"..., "rootfs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "idefs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "usbfs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "ram") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "NI=") = NULL
fclose(0x80597e0) = 0
open("/dev/fd0", 0, 01001313740) = -1
fopen("/proc/cmdline", "r") = 0x80597e0
memset(0xbffff890, '\000', 128) = 0xbffff890
fgets("ro root=LABEL=/ acpi=force conso"..., 128, 0x80597e0) = 0xbffff890
strstr("ro root=LABEL=/ acpi=force conso"..., "rootfs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "idefs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "usbfs") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "ram") = NULL
strstr("ro root=LABEL=/ acpi=force conso"..., "NI=") = NULL
fclose(0x80597e0) = 0
mkdir("/tmp/pkg", 0755) = -1
mkdir("/tmp/etc", 0755) = -1
mkdir("/etc/.config/", 0755) = -1
printf("==>> Read error - %d\n", 1==>> Read error - 1
) = 20
--- SIGINT (Interrupt) ---
+++ killed by SIGINT +++
通过上面太美对 BBIagent 目录结构的分析可以看出,它不仅像 busybox 那样将有一些功能压缩到一个文件 init 中(比如各种 .cgi 文件),还将用到的各种 bin 也放到了 ifconfig 中,这是之前没有发现的
学过 C 语言的人都知道,main 函数有 argc 和 argv 两个参数,其中存放参数那个二维数组的第一个一维字符串就是所执行的程序自身的名称,busybox 通过这种方法来是先执行一个程序达到不同效果的
之后的测试更加证实了我的想法,其实 ifconfig 就是将 busybox 改了名字而已
[root@PT_LINUX sbin]# ll
total 384
-rw-r--r-- 1 root root 11161 Feb 5 23:17 a
-rwxr-xr-x 2 root root 102584 Apr 11 2005 ifconfig
-rwxr-xr-x 1 root root 68384 Aug 18 15:41 init
-rwxr-xr-x 1 root root 40648 Apr 9 2005 iptables
-rwxr-xr-x 1 root root 42020 Apr 9 2005 mini_httpd
[root@PT_LINUX sbin]# cp ifconfig busybox
[root@PT_LINUX sbin]# ll
total 276
-rw-r--r-- 1 root root 11161 Feb 5 23:17 a
-rwxr-xr-x 1 root root 102584 Apr 11 2005 busybox
-rwxr-xr-x 1 root root 102584 Apr 11 2005 ifconfig
-rwxr-xr-x 1 root root 68384 Aug 18 15:41 init
-rwxr-xr-x 1 root root 40648 Apr 9 2005 iptables
-rwxr-xr-x 1 root root 42020 Apr 9 2005 mini_httpd
[root@PT_LINUX sbin]# ./busybox
BusyBox v1.00 (2005.04.11-08:11+0000) Built-in shell (msh)
Enter 'help' for a list of built-in commands.
# exit
[root@PT_LINUX sbin]#
其实 init 也是同理,和 busybox 类似,我们之所以看不到 rootfs 展开后有什么东西,是由于大多数后期展开工作是由 init 来完成的
用同样的思想,又做了下面的测试
[root@PT_LINUX sbin]# ll
total 276
-rw-r--r-- 1 root root 11161 Feb 5 23:17 a
lrwxrwxrwx 1 root root 4 Feb 6 01:11 get.cgi -> init
-rwxr-xr-x 1 root root 102584 Apr 11 2005 ifconfig
lrwxrwxrwx 1 root root 4 Feb 6 01:10 index.cgi -> init
-rwxr-xr-x 1 root root 68384 Aug 18 15:41 init
-rwxr-xr-x 1 root root 40648 Apr 9 2005 iptables
-rwxr-xr-x 1 root root 42020 Apr 9 2005 mini_httpd
lrwxrwxrwx 1 root root 4 Feb 6 01:11 put.cgi -> init
lrwxrwxrwx 1 root root 4 Feb 6 01:10 reg.cgi -> init
lrwxrwxrwx 1 root root 4 Feb 6 01:11 run.cgi -> init
lrwxrwxrwx 1 root root 8 Feb 6 01:07 sh -> ifconfig
[root@PT_LINUX sbin]# ./reg.cgi
[root@PT_LINUX sbin]# ltrace ./reg.cgi
__uClibc_start_main(1, 0xbffffb14, 0xbffffb1c, 0x8049300, 0x8055128
malloc(1024) = 0x8058f48
malloc(1024) = 0x8059350
malloc(128) = 0x8059758
__xpg_basename(0xbffffc0e, 0xbffffaec, 0x400008c6, 0x4000524c, 2704) = 0xbffffc10
openlog("reg.cgi", 1, 176) =
strcmp("reg.cgi", "connect") = 1
strcmp("reg.cgi", "sconf") = -1
strcmp("reg.cgi", "init") = 1
strcmp("reg.cgi", "index.cgi") = 1
strcmp("reg.cgi", "put.cgi") = 1
strcmp("reg.cgi", "get.cgi") = 1
strcmp("reg.cgi", "run.cgi") = -1
strcmp("reg.cgi", "reg.cgi") = 0
getenv("HTTP_COOKIE") = NULL
closelog() =
exit(99
+++ exited (status 99) +++
[root@PT_LINUX sbin]#
暂时只有这些能耐了,希望这些信息对太美能够有所帮助 ^_^
[ 本帖最后由 platinum 于 2006-2-6 01:54 编辑 ] |
|