环境
关于路由环境的搭建可以参考这篇博客 Linux路由配置实战(不同网段通信)
最终搭建环境如下:
虚拟机 | 说明 |
---|---|
centos7.0 | 路由器 172.16.17.196 + 192.168.43.104 |
windows 7 A | 通信A端 192.168.43.79 |
ubuntu18.04 B1 | 通信B端 172.16.17.199 |
ubuntu18.04 B2 | 通信B端 172.16.17.194 |
SSH链接
1、通信B端设置SSH的服务端
# debian/deepin/ubuntu
sudo apt install openssh-server
# 启动ssh服务
sudo systemctl start sshd
# 设置ssh开机自启动
sudo systemctl enable sshd
2、通信A端链接(利用putty)
链接B2
链接B1
IP欺骗配置
通过hook路由器的netfilter防火墙可以实现,具体代码就不粘了,有想学习的同学可以找我私聊
主要代码如下:
改变daddr:
#include <net/ip.h>
#include <net/tcp.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/init.h>
#include <linux/inet.h> /*in_aton()*/
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/module.h>
#include <linux/socket.h>/*PF_INET*/
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>/*NF_IP_PRE_FIRST*/
#define ETHALEN 14
#define NIPQUAD(addr) \
((unsigned char *)&addr)[0], \
((unsigned char *)&addr)[1], \
((unsigned char *)&addr)[2], \
((unsigned char *)&addr)[3]
__be32 sip,dip;
static struct nf_hook_ops nfho1, nfho2;
char tmp_ip[20];//存储初始的目的IP地址
unsigned int tcpsend(unsigned int hooknum,
struct sk_buff *__skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *skb;
struct net_device *dev;
struct iphdr *iph;
struct tcphdr *tcph;
int tot_len;
int iph_len;
int tcph_len;
skb = __skb;
if (skb == NULL)
return NF_ACCEPT;
iph = ip_hdr(skb);
if (iph == NULL)
return NF_ACCEPT;
tot_len = ntohs(iph->tot_len);
if (iph->daddr == in_aton("172.16.17.199"))
{
iph_len = ip_hdrlen(skb);/*in ip.h*/
//skb_pull(skb, iph_len); //skb->data指针定位到了传输层
//skb_reset_transport_header(skb);//重置首部长度,现在的首部长度包括了的ip首部长度
if (iph->protocol == IPPROTO_TCP)
{
printk("daddr change to 172.16.17.194\n");
iph->daddr = in_aton("172.16.17.194");
tcph = tcp_hdr(skb);
tcph_len = tcp_hdrlen(skb);
dev = dev_get_by_name(&init_net, "ens33");
tcph->check = 0;
skb->