Skip to content

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofroes committed Mar 1, 2021
1 parent 202d5a9 commit e4da668
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
14 changes: 11 additions & 3 deletions pkg/scrapy/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gocolly/colly"
)

func ParseMSDNFunction(url string) *utils.API{
func ParseMSDNFunction(search, url string) *utils.API{
api := utils.API{}

collector := colly.NewCollector(
Expand All @@ -21,6 +21,12 @@ func ParseMSDNFunction(url string) *utils.API{

collector.OnHTML("meta", func(e *colly.HTMLElement){
if e.Attr("property") == "og:title"{
funcTitle := strings.Split(strings.ToLower(e.Attr("content")), " ")[0]

if(!strings.Contains(funcTitle, search)){
utils.Warning("Unable to find this Windows function.")
}

api.Title = e.Attr("content")
return
}
Expand Down Expand Up @@ -73,6 +79,8 @@ func ParseMSDNFunction(url string) *utils.API{
}

func RunFunctionScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
searchAux := "+api+function+msdn"
Expand All @@ -83,7 +91,7 @@ func RunFunctionScraper(search, cachePath string){
utils.Warning("Unable to find this Windows function.")
}

api := ParseMSDNFunction(url)
api := ParseMSDNFunction(search, url)

cache.RunFunctionCache(search, cachePath, api)
}
Expand All @@ -96,7 +104,7 @@ func RunFunctionScraper(search, cachePath string){
utils.Warning("Unable to find this Windows function.")
}

api := ParseMSDNFunction(url)
api := ParseMSDNFunction(search, url)

utils.PrintMSDNFunc(api)
}
Expand Down
21 changes: 17 additions & 4 deletions pkg/scrapy/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@ package scrapy

import(
"log"
"strings"

"github.com/leandrofroes/manw/pkg/utils"
"github.com/leandrofroes/manw/pkg/cache"

"github.com/gocolly/colly"
)

func parseKernelInfo(url string) string{
func parseKernelInfo(search, url string) string{
var kernelInfo string
collector := colly.NewCollector(
colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"),
)

collector.OnHTML("title", func(e *colly.HTMLElement){
strucTitle := strings.ToLower(strings.Split(e.Text, " ")[1])

if(!strings.Contains(strucTitle, search)){
utils.Warning("Unable to find this Windows Kernel structure.")
}

kernelInfo = e.Text
})

collector.OnHTML("pre", func(e *colly.HTMLElement){
if(e.Attr("class") == "kernelstruct"){
kernelInfo = e.Text
Expand All @@ -31,6 +42,8 @@ func parseKernelInfo(url string) string{
}

func RunKernelScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
searchAux := "+kernel+struct+nirsoft"
Expand All @@ -41,7 +54,7 @@ func RunKernelScraper(search, cachePath string){
utils.Warning("Unable to find this Windows Kernel structure.")
}

kernelInfo := parseKernelInfo(url)
kernelInfo := parseKernelInfo(search, url)

cache.RunKernelCache(search, kernelInfo, cachePath)
}
Expand All @@ -54,8 +67,8 @@ func RunKernelScraper(search, cachePath string){
utils.Warning("Unable to find this Windows Kernel structure.")
}

kernelInfo := parseKernelInfo(url)
kernelInfo := parseKernelInfo(search, url)

utils.GenericPrint(kernelInfo)
}
}
16 changes: 12 additions & 4 deletions pkg/scrapy/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gocolly/colly"
)

func ParseMSDNStructure(url string) *utils.API{
func ParseMSDNStructure(search, url string) *utils.API{
api := utils.API{}

collector := colly.NewCollector(
Expand All @@ -21,6 +21,12 @@ func ParseMSDNStructure(url string) *utils.API{

collector.OnHTML("meta", func(e *colly.HTMLElement){
if e.Attr("property") == "og:title"{
strucTitle := strings.Split(strings.ToLower(e.Attr("content")), " ")[0]

if(!strings.Contains(strucTitle, search)){
utils.Warning("Unable to find this Windows structure.")
}

api.Title = e.Attr("content")
return
}
Expand Down Expand Up @@ -70,6 +76,8 @@ func ParseMSDNStructure(url string) *utils.API{
}

func RunStructureScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
searchAux := "+structure+msdn"
Expand All @@ -80,7 +88,7 @@ func RunStructureScraper(search, cachePath string){
utils.Warning("Unable to find this Windows structure.")
}

api := ParseMSDNStructure(url)
api := ParseMSDNStructure(search, url)

cache.RunStructureCache(search, cachePath, api)
}
Expand All @@ -93,8 +101,8 @@ func RunStructureScraper(search, cachePath string){
utils.Warning("Unable to find this Windows structure.")
}

api := ParseMSDNStructure(url)
api := ParseMSDNStructure(search, url)

utils.PrintMSDNStructure(api)
}
}
9 changes: 8 additions & 1 deletion pkg/scrapy/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import(
"net/http"
"io/ioutil"
"strings"
"regexp"

"github.com/leandrofroes/manw/pkg/utils"
"github.com/leandrofroes/manw/pkg/cache"
Expand All @@ -19,7 +20,11 @@ func parseSyscallRepo(search, url string) map[string]interface{}{
body, err := ioutil.ReadAll(r.Body)
utils.CheckError(err)

if(!strings.Contains(string(body), search)){
re, err := regexp.Compile("\"+" + search + "\":")
utils.CheckError(err)
match := re.FindString(strings.ToLower(string(body)))

if(match == ""){
utils.Warning("Unable to find this Windows Syscall ID.")
}

Expand All @@ -32,6 +37,8 @@ func parseSyscallRepo(search, url string) map[string]interface{}{
func RunSyscallScraper(search, arch, cachePath string){
var url string

search = strings.ToLower(search)

if(arch == "x64" || arch == "amd64" || arch == "x86_64" ){
url = "https://raw.githubusercontent.com/j00ru/windows-syscalls/master/x64/json/nt-per-system.json"
arch = "_x64"
Expand Down
14 changes: 12 additions & 2 deletions pkg/scrapy/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import(
"github.com/gocolly/colly"
)

func parseMSDNDataType(s, url string) string{
func parseMSDNDataType(search, url string) string{
var dataTypeInfo string
collector := colly.NewCollector(
colly.AllowedDomains("docs.microsoft.com"),
colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"),
)

collector.OnHTML("tr", func(e *colly.HTMLElement){
str := strings.ToUpper(s) + "\n"
str := strings.ToUpper(search) + "\n"
re, err := regexp.Compile(str)
utils.CheckError(err)
match := re.FindString(e.Text)
Expand All @@ -46,6 +46,8 @@ func parseMSDNDataType(s, url string) string{
}

func RunTypeScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
searchAux := "+windows+data+type+msdn"
Expand All @@ -58,6 +60,10 @@ func RunTypeScraper(search, cachePath string){

dataTypeInfo := parseMSDNDataType(search, url)

if(dataTypeInfo == ""){
utils.Warning("Unable to find this Windows data type.")
}

cache.RunTypeCache(search, dataTypeInfo, cachePath)
}
} else {
Expand All @@ -71,6 +77,10 @@ func RunTypeScraper(search, cachePath string){

dataTypeInfo := parseMSDNDataType(search, url)

if(dataTypeInfo == ""){
utils.Warning("Unable to find this Windows data type.")
}

utils.GenericPrint(dataTypeInfo)
}
}

0 comments on commit e4da668

Please sign in to comment.