iT邦幫忙

2023 iThome 鐵人賽

DAY 5
0
SideProject30

DDOS:閑的沒事就開始DDOS系列 第 5

[Day 5] 閑的沒事就建立socket - sys

  • 分享至 

  • xImage
  •  

在syscall還未被棄用的時後是用syscall建立socket指定來源PORT。現在使用sys
(主題是做DDOS,其實有沒有指定PORT不是重點,但這個在後面做raw socket是重點)

Overview

This repository holds supplemental Go packages for low-level interactions with the operating system.

Directories

packet description
cpu Package cpu implements processor feature detection for various CPU architectures.
execabs Package execabs is a drop-in replacement for os/exec that requires PATH lookups to find absolute paths.
unix Package unix contains an interface to the low-level operating system primitives.
windows Package windows contains an interface to the low-level operating system primitives.

做socket用到sys.unix庫

Socket

package main

import (
	"fmt"
	"log"
	"net"

	"golang.org/x/sys/unix"
)

func main() {
	srcIP := "0.0.0.0"  // if not know, set 0.0.0.0
	srcPort := 23457
	targetIP := "10.211.55.10"
	targetPort := 12345

	// build socket
	fd, err := unix.Socket(unix.AF_INET, unix.SOCK_STREAM, unix.IPPROTO_TCP)
	if err != nil {
		log.Fatal(err)
	}
	defer unix.Close(fd)

	// set source IP and source PORT
	localAddr := &unix.SockaddrInet4{Port: srcPort}
	copy(localAddr.Addr[:], net.ParseIP(srcIP).To4())

	err = unix.Bind(fd, localAddr)
	if err != nil {
		log.Fatal(err)
	}

	// connnect
	remoteAddr := &unix.SockaddrInet4{Port: targetPort}
	copy(remoteAddr.Addr[:], net.ParseIP(targetIP).To4())

	err = unix.Connect(fd, remoteAddr)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("SYN packet sent successfully!")
}


上一篇
[Day 4] 閑的沒事 - 來源端口(踩坑)
下一篇
[Day 6] 閑的沒事就攔截封包 - 封包解析
系列文
DDOS:閑的沒事就開始DDOS31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言