2020-04-06 03:19:32 +09:00
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"golang.org/x/net/html"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
/ *
template
| [ WebHackersWeapons ] ( https : //github.com/hahwul/WebHackersWeapons) | template |  |  | <br> <br>  <br>  |
* /
type Tools struct {
2020-04-07 23:52:40 +09:00
Type , Data , Method string
2020-04-06 03:19:32 +09:00
}
func isTitleElement ( n * html . Node ) bool {
return n . Type == html . ElementNode && n . Data == "title"
}
func traverse ( n * html . Node ) ( string , bool ) {
if isTitleElement ( n ) {
return n . FirstChild . Data , true
}
for c := n . FirstChild ; c != nil ; c = c . NextSibling {
result , ok := traverse ( c )
if ok {
return result , ok
}
}
return "" , false
}
func GetHtmlTitle ( r io . Reader ) ( string , bool ) {
doc , err := html . Parse ( r )
if err != nil {
panic ( "Fail to parse html" )
}
return traverse ( doc )
}
2020-04-07 23:52:40 +09:00
func writeJSON ( category string , name string , method string , data string ) {
2020-04-06 03:19:32 +09:00
jsonFile , err := os . Open ( "data.json" )
// if we os.Open returns an error then handle it
if err != nil {
fmt . Println ( err )
}
fmt . Println ( "Successfully Opened data.json" )
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile . Close ( )
byteValue , _ := ioutil . ReadAll ( jsonFile )
var result map [ string ] interface { }
json . Unmarshal ( [ ] byte ( byteValue ) , & result )
tool := Tools {
2020-04-07 23:52:40 +09:00
Type : category ,
Data : data ,
Method : method ,
2020-04-06 03:19:32 +09:00
}
result [ name ] = tool
file , _ := json . MarshalIndent ( result , "" , " " )
_ = ioutil . WriteFile ( "data.json" , file , 0644 )
}
func main ( ) {
2020-04-08 02:13:26 +09:00
repourl := flag . String ( "url" , "" , "any url" )
2020-04-06 03:19:32 +09:00
first := flag . Bool ( "isFirst" , false , "if you add new type, it use" )
flag . Parse ( )
if flag . NFlag ( ) == 0 {
flag . Usage ( )
return
}
u , err := url . Parse ( * repourl )
if err != nil {
panic ( err )
}
if u . Host == "github.com" {
//fmt.Println(u.Path)
name := strings . Split ( u . Path , "/" ) [ 2 ]
//fmt.Println(name)
desc := "asdf"
resp , err := http . Get ( * repourl )
if err != nil {
panic ( err )
}
defer resp . Body . Close ( )
if title , ok := GetHtmlTitle ( resp . Body ) ; ok {
2020-04-11 02:28:57 +09:00
if strings . Contains ( string ( title ) , ": " ) {
desc = strings . Split ( string ( title ) , ": " ) [ 1 ]
} else {
reader1 := bufio . NewReader ( os . Stdin )
fmt . Println ( "[+] Don't have descriptions / input description" )
a , _ := reader1 . ReadString ( '\n' )
desc = strings . TrimRight ( a , "\r\n" )
}
2020-04-06 03:19:32 +09:00
} else {
println ( "Fail to get HTML title" )
}
typeFile , err := os . Open ( "type.lst" )
// if we os.Open returns an error then handle it
if err != nil {
fmt . Println ( err )
}
fmt . Println ( "Successfully Opened type.lst" )
// defer the closing of our jsonFile so that we can parse it later on
defer typeFile . Close ( )
index := 0
m := make ( map [ int ] string )
reader := bufio . NewReader ( typeFile )
for {
line , isPrefix , err := reader . ReadLine ( )
if isPrefix || err != nil {
break
}
m [ index ] = string ( line )
fmt . Println ( "[" + strconv . Itoa ( index ) + "] " + string ( line ) )
index = index + 1
}
var choicetype int
2020-04-07 23:52:40 +09:00
fmt . Println ( "[+] What is type?" )
2020-04-06 03:19:32 +09:00
_ , err = fmt . Scan ( & choicetype )
fmt . Println ( m [ choicetype ] )
2020-04-07 23:52:40 +09:00
reader1 := bufio . NewReader ( os . Stdin )
fmt . Println ( "[+] What is method(e.g XSS, WVS, SSL, ETC..)?" )
method , _ := reader1 . ReadString ( '\n' )
method = strings . TrimRight ( method , "\r\n" )
2020-04-08 00:29:23 +09:00
writeJSON ( m [ choicetype ] , name , method , "| " + m [ choicetype ] + "/" + method + " | [" + name + "](" + * repourl + ") | " + desc + " |  |  |" )
2020-04-06 03:19:32 +09:00
} else {
reader := bufio . NewReader ( os . Stdin )
fmt . Println ( "[+] What is name?" )
name , _ := reader . ReadString ( '\n' )
name = strings . TrimRight ( name , "\r\n" )
fmt . Println ( "[+] Input Description?" )
udesc , _ := reader . ReadString ( '\n' )
udesc = strings . TrimRight ( udesc , "\r\n" )
typeFile , err := os . Open ( "type.lst" )
// if we os.Open returns an error then handle it
if err != nil {
fmt . Println ( err )
}
fmt . Println ( "Successfully Opened type.lst" )
// defer the closing of our jsonFile so that we can parse it later on
defer typeFile . Close ( )
index := 0
m := make ( map [ int ] string )
readerF := bufio . NewReader ( typeFile )
for {
line , isPrefix , err := readerF . ReadLine ( )
if isPrefix || err != nil {
break
}
m [ index ] = string ( line )
fmt . Println ( "[" + strconv . Itoa ( index ) + "] " + string ( line ) )
index = index + 1
}
var choicetype int
fmt . Println ( "What is type?" )
_ , err = fmt . Scan ( & choicetype )
fmt . Println ( m [ choicetype ] )
2020-04-07 23:52:40 +09:00
reader1 := bufio . NewReader ( os . Stdin )
fmt . Println ( "[+] What is method(e.g XSS, WVS, SSL, ETC..)?" )
method , _ := reader1 . ReadString ( '\n' )
method = strings . TrimRight ( method , "\r\n" )
2020-04-11 00:17:42 +09:00
writeJSON ( m [ choicetype ] , name , method , "| " + m [ choicetype ] + "/" + method + " | [" + name + "](" + * repourl + ") | " + udesc + "||" )
2020-04-06 03:19:32 +09:00
}
if * first {
2020-04-07 23:52:40 +09:00
fmt . Println ( "| Type | Name | Description | Popularity | Language |" )
2020-04-06 03:19:32 +09:00
fmt . Println ( "| ---------- | :---------- | :----------: | :----------: | :----------: |" )
}
//fmt.Println("| [" + name + "](" + *repourl + ") | " + desc + " |  |  | <br> <br>  <br>  |")
}