libpcap을 이용하여 send packet 만드는데요..

woojisung의 이미지

libpcap을 이용하여 send packet을 만들려고합니다..
winpcap을 응용하여 리눅스 CentOS5에서 libpcap으로

소스를 건드려가면서 하는중인데요...
일단 ARP를 타겟 IP에 보내서 그 타겟 IP가 맥주소를 response
해주면 성공입니다..

지금까지 짠 소스는 이정도인데.. 소스 정리와 추가할것좀 알려주세요.
주석달아주시면서 간단한 설명도 첨부해주시면 감사하겠습니다..
그리고 ARP말고도 IP,TCP등등의 것들의 소스도 올려주시면 감사하겠습니다.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define PROMISCUOUS 1
#define NONPROMISCUOUS 0

void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
u_char packet[100];
char *dev;
int i;

dev = pcap_lookupdev(errbuf);

if( dev == NULL )
{
printf("%s\n", errbuf);
exit(1);
}

if(argc !=2)
{

printf("usage : %s interface (e.g. 'rpcap://eth0')", argv[0]);
return;
}

if ( (fp = pcap_open_live(dev, BUFSIZ, NONPROMISCUOUS, 0, errbuf)) == NULL)
{
printf(stderr, "Unable to open the Adapter.%s is not supported by Libpcap ", argv[1]);
return;
}

/* Supposing to be on ethernet, set mac destination to */
packet[0] = 0xFF;
packet[1] = 0xFF;
packet[2] = 0xFF;
packet[3] = 0xFF;
packet[4] = 0xFF;
packet[5] = 0xFF;

/* set mac source to */
packet[6] = 0x00;
packet[7] = 0x11;
packet[8] = 0x22;
packet[9] = 0x33;
packet[10] = 0x44;
packet[11] = 0x55;

/* ARP */
packet[12] = 0x08;
packet[13] = 0x06;

/* Hardware Type (ethernet) */
packet[14] = 0x00;
packet[15] = 0x01;

/* protocol type(ip) */
packet[16] = 0x08;
packet[17] = 0x00;

/* Hardware Length */
packet[18] = 0x06;

/* Protocol Length */
packet[19] = 0x04;

/* Operation (request :1, reply : 2) */
packet[20] = 0x01;
packet[21] = 0x02;

/* Sender Hardware Address */
packet[22] = 0x00;
packet[23] = 0x0C;
packet[24] = 0x29;
packet[25] = 0x71;
packet[26] = 0x4C;
packet[27] = 0x2D;

/* Sender Protocol Address */
packet[28] = 0xC0;
packet[29] = 0xA8;
packet[30] = 0xF7;
packet[31] = 0x82;

/* Target Hardware Address (Empty) */
packet[32] = 0xFF;
packet[33] = 0xFF;
packet[34] = 0xFF;
packet[35] = 0xFF;
packet[36] = 0xFF;
packet[37] = 0xFF;
/*
packet[32] = 0x00;
packet[33] = 0x0E;
packet[34] = 0xE8;
packet[35] = 0xE8;
packet[36] = 0xEC;
packet[37] = 0x5E;
*/
/* Target Protocol Address */
packet[38] = 0xC0;
packet[39] = 0xA8;
packet[40] = 0x00;
packet[41] = 0x04;

/* file the rest of the packet */
for( i=12 ; i<100 ; i++ )
{
packet[i] = i%256;
}

if (pcap_sendpacket(fp, packet, 100 /* size */ ) != 0 )
{
printf(stderr, "\nError sending the packet: \n", pcap_geterr(fp));
return;
}
return;
}

powerson의 이미지

winpcap에서는 지원하는 걸로 알고 있지만, linux의 libpcap에서는 packet을 sending 하는 것을 지원하지 않는 걸로 알고 있습니다. 혹시 최신버전에서는 지원하는 건가요? 그래서 libnet을 이용해서 packet sending 하는 걸로 알고 있습니다만..

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.