IP欺骗之SSH链接

环境

关于路由环境的搭建可以参考这篇博客 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->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值