Skip to content

Commit db1ec78

Browse files
committed
feat: add google search in site data
Made improvements - add google search in site data - fix precisely mode - optimize code structure
1 parent a37530c commit db1ec78

File tree

5 files changed

+369
-120
lines changed

5 files changed

+369
-120
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ Usage:
3131
3232
Flags:
3333
-c, --check self-check
34+
-f, --file string Site data file (default "data.json")
3435
-h, --help help for detect
3536
-n, --name strings name[s]
36-
--nsfw Include checking of NSFW sites from default list.
37+
--nsfw Include checking of NSFW sites from default list.
3738
--precisely Check precisely
38-
-p, --proxy string Make requests over a proxy. e.g. socks5://127.0.0.1:1080
39-
-s, --site strings Limit analysis to just the listed sites. Add multiple opt
40-
ions to specify more than one site.
41-
-t, --timeout int Time (in seconds) to wait for response to requests (defau
42-
lt 60)
39+
-p, --proxy string Make requests over a proxy. e.g. socks5://127.0.0.1:1080
40+
-r, --retry int Retry times after request failed (default 3)
41+
-s, --site strings Limit analysis to just the listed sites. Add multiple options to specify more than one site.
42+
-t, --timeout int Time (in seconds) to wait for response to requests (default 10)
4343
4444
Global Flags:
4545
-v, --verbose verbose output
46+
4647
```
4748

4849
To search for only one user:

README_ZH.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ Usage:
2929
3030
Flags:
3131
-c, --check self-check
32+
-f, --file string Site data file (default "data.json")
3233
-h, --help help for detect
3334
-n, --name strings name[s]
34-
--nsfw Include checking of NSFW sites from default list.
35+
--nsfw Include checking of NSFW sites from default list.
3536
--precisely Check precisely
36-
-p, --proxy string Make requests over a proxy. e.g. socks5://127.0.0.1:1080
37-
-s, --site strings Limit analysis to just the listed sites. Add multiple opt
38-
ions to specify more than one site.
39-
-t, --timeout int Time (in seconds) to wait for response to requests (defau
40-
lt 60)
37+
-p, --proxy string Make requests over a proxy. e.g. socks5://127.0.0.1:1080
38+
-r, --retry int Retry times after request failed (default 3)
39+
-s, --site strings Limit analysis to just the listed sites. Add multiple options to specify more than one site.
40+
-t, --timeout int Time (in seconds) to wait for response to requests (default 10)
4141
4242
Global Flags:
4343
-v, --verbose verbose output

cmd/detect.go

Lines changed: 129 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ var (
3535
reqErrorInfo = "[!] %-15s %-15s: %s requests error, retry %d/%d\n"
3636
sleepMap = make(map[string]int64)
3737
sleepChannel = make(map[string]chan bool)
38+
searchInfo = "[+] %-15s %-15s: Please check in %s\n"
3839
)
3940

4041
func init() {
4142
detectCmd.Flags().StringSliceVarP(&detectArgs.name, "name", "n", []string{}, "name[s]")
42-
_ = detectCmd.MarkFlagRequired("name")
43+
//_ = detectCmd.MarkFlagRequired("name")
4344
detectCmd.Flags().StringSliceVarP(&detectArgs.site, "site", "s", []string{}, "Limit analysis to just the listed sites. Add multiple options to specify more than one site.")
4445
detectCmd.Flags().BoolVarP(&detectArgs.check, "check", "c", false, "self-check")
4546
detectCmd.Flags().StringVarP(&detectArgs.proxy, "proxy", "p", "", "Make requests over a proxy. e.g. socks5://127.0.0.1:1080")
46-
detectCmd.Flags().IntVarP(&detectArgs.timeout, "timeout", "t", 30, "Time (in seconds) to wait for response to requests")
47+
detectCmd.Flags().IntVarP(&detectArgs.timeout, "timeout", "t", 10, "Time (in seconds) to wait for response to requests")
4748
detectCmd.Flags().BoolVar(&detectArgs.isNSFW, "nsfw", false, "Include checking of NSFW sites from default list.")
4849
detectCmd.Flags().IntVarP(&detectArgs.retry, "retry", "r", 3, "Retry times after request failed")
4950
detectCmd.Flags().BoolVar(&detectArgs.precisely, "precisely", false, "Check precisely")
@@ -55,7 +56,7 @@ func init() {
5556

5657
var detectCmd = &cobra.Command{
5758
Use: "detect",
58-
Short: "Hunt down social media accounts by username across social networks",
59+
Short: "Hunt down social media accounts by username, email or phone across social networks",
5960
Long: ``,
6061
Run: detect,
6162
}
@@ -93,10 +94,14 @@ func detect(_ *cobra.Command, _ []string) {
9394
}
9495
}
9596

96-
for _, name := range detectArgs.name {
97-
for site, siteBody := range siteDataMap {
98-
go detectSite(name, site, siteBody)
99-
wg.Add(1)
97+
if detectArgs.check {
98+
log.Infoln("self check")
99+
} else {
100+
for _, name := range detectArgs.name {
101+
for site, siteBody := range siteDataMap {
102+
go detectSite(name, site, siteBody)
103+
wg.Add(1)
104+
}
100105
}
101106
}
102107
wg.Wait()
@@ -127,122 +132,141 @@ func detectSite(name, site string, siteBody gjson.Result) {
127132

128133
detectReq := siteBody.Get("detect").Array()
129134

130-
retryTimes := 0
135+
detectCount := len(detectReq) - 1
131136
for index, detectData := range detectReq {
137+
retryTimes := 0
138+
if detectUser(name, site, index, retryTimes, detectCount, &flag, detectData) {
139+
continue
140+
} else {
141+
break
142+
}
143+
}
144+
}
132145

133-
// set header
134-
header := make(map[string]string)
135-
if h := detectData.Get("header"); h.Exists() {
136-
headerTemp, ok := h.Value().(map[string]interface{})
137-
if !ok {
138-
log.Fatalln(headerTemp, "is invalid")
139-
}
140-
for key, value := range headerTemp {
141-
strKey := fmt.Sprintf("%v", key)
142-
strValue := fmt.Sprintf("%v", value)
143-
header[strKey] = strValue
144-
}
146+
func detectUser(name, site string, requestTimes, retryTimes, detectCount int, flag *bool, detectData gjson.Result) bool {
145147

148+
// set header
149+
header := make(map[string]string)
150+
if h := detectData.Get("header"); h.Exists() {
151+
headerTemp, ok := h.Value().(map[string]interface{})
152+
if !ok {
153+
log.Fatalln(headerTemp, "is invalid")
146154
}
147-
148-
// if body is set, set method to post
149-
var body string
150-
if d := detectData.Get("body"); d.Exists() {
151-
body = d.String()
152-
if strings.Contains(body, "%s") {
153-
body = fmt.Sprintf(body, name)
154-
}
155+
for key, value := range headerTemp {
156+
strKey := fmt.Sprintf("%v", key)
157+
strValue := fmt.Sprintf("%v", value)
158+
header[strKey] = strValue
155159
}
156160

157-
// set url with name
158-
var url string
159-
if u := detectData.Get("url"); u.Exists() {
160-
url = u.String()
161-
if strings.Contains(url, "%s") {
162-
url = fmt.Sprintf(url, name)
163-
}
164-
} else {
165-
log.Fatalln("Why no URL???")
166-
}
161+
}
167162

168-
// delay
169-
if ch, ok := sleepChannel[site]; ok {
170-
ch <- true
171-
time.Sleep(time.Duration(sleepMap[site]) * time.Second)
172-
<-ch
163+
// if body is set, set method to post
164+
var body string
165+
if d := detectData.Get("body"); d.Exists() {
166+
body = d.String()
167+
if strings.Contains(body, "%s") {
168+
body = fmt.Sprintf(body, name)
173169
}
170+
}
174171

175-
var rep *resty.Response
176-
for retryTimes < detectArgs.retry {
177-
var err error
178-
rep, err = utils.Requests(url, body, detectArgs.proxy, header, detectArgs.timeout)
179-
if err != nil {
180-
retryTimes += 1
181-
log.Debugf(reqErrorInfo, name, site, url, retryTimes, detectArgs.retry)
182-
time.Sleep(time.Duration(sleepMap[site]) * time.Second)
183-
continue
184-
}
185-
break
172+
// set url with name
173+
var url string
174+
if u := detectData.Get("url"); u.Exists() {
175+
url = u.String()
176+
if strings.Contains(url, "%s") {
177+
url = fmt.Sprintf(url, name)
186178
}
187-
188-
if retryTimes == detectArgs.retry {
189-
log.Infof(reqErrorInfo, name, site, url, retryTimes, detectArgs.retry)
190-
break
179+
} else if search := detectData.Get("search"); search.Exists() {
180+
searchString := search.String()
181+
if strings.Contains(searchString, "%s") {
182+
searchString = fmt.Sprintf(searchString, name)
191183
}
184+
searchUrl := fmt.Sprintf(detectData.Get("searchUrl").String(), searchString)
185+
log.Infof(searchInfo, name, site, searchUrl)
186+
return false
187+
} else {
188+
log.Fatalln("Why no URL???")
189+
}
192190

193-
//log.Infoln(rep.Request.Body)
194-
//log.Debugln(rep.Status())
195-
//log.Debugln(rep.Proto())
196-
//
197-
//log.Debugln(rep.Request.Header)
198-
//
199-
//log.Debugln(rep.String())
200-
201-
// statusCode, existRegex must both be true
202-
statusCode := detectData.Get("statusCode")
203-
existRegex := detectData.Get("existRegex")
204-
205-
statusCodeCheck := !statusCode.Exists() || strings.Contains(rep.Status(), statusCode.String())
206-
existRegexCheck := true
207-
if existRegex.Exists() && len(existRegex.Str) != 0 {
208-
match, err := regexp.MatchString(existRegex.String(), rep.String())
209-
if err != nil {
210-
log.Errorln(err)
211-
}
212-
existRegexCheck = match
213-
}
191+
// delay
192+
if ch, ok := sleepChannel[site]; ok {
193+
ch <- true
194+
time.Sleep(time.Duration(sleepMap[site]) * time.Second)
195+
<-ch
196+
}
214197

215-
// nonExistRegex have a veto power
216-
nonExistRegex := detectData.Get("nonExistRegex")
217-
nonExistRegexCheck := false
218-
if nonExistRegex.Exists() && len(nonExistRegex.Str) != 0 {
219-
match, err := regexp.MatchString(nonExistRegex.String(), rep.String())
220-
if err != nil {
221-
log.Errorln(err)
222-
}
223-
nonExistRegexCheck = match
224-
}
225-
if statusCodeCheck && existRegexCheck && !nonExistRegexCheck {
226-
flag = true
198+
var rep *resty.Response
199+
for retryTimes < detectArgs.retry {
200+
var err error
201+
rep, err = utils.Requests(url, body, detectArgs.proxy, header, detectArgs.timeout)
202+
if err != nil {
203+
retryTimes += 1
204+
log.Debugf(reqErrorInfo, name, site, url, retryTimes, detectArgs.retry)
205+
time.Sleep(time.Duration(sleepMap[site]) * time.Second)
206+
continue
227207
}
208+
break
209+
}
210+
211+
if retryTimes == detectArgs.retry {
212+
log.Infof(reqErrorInfo, name, site, url, retryTimes, detectArgs.retry)
213+
return false
214+
}
228215

229-
userPage := detectData.Get("userPage").String()
230-
if strings.Contains(userPage, "%s") {
231-
userPage = fmt.Sprintf(userPage, name)
216+
//log.Infoln(rep.Request.Body)
217+
//log.Debugln(rep.Status())
218+
//log.Debugln(rep.Proto())
219+
//
220+
//log.Debugln(rep.Request.Header)
221+
//
222+
//log.Debugln(rep.String())
223+
224+
// statusCode, existRegex must both be true
225+
statusCode := detectData.Get("statusCode")
226+
existRegex := detectData.Get("existRegex")
227+
228+
statusCodeCheck := !statusCode.Exists() || strings.Contains(rep.Status(), statusCode.String())
229+
existRegexCheck := true
230+
if existRegex.Exists() && len(existRegex.Str) != 0 {
231+
match, err := regexp.MatchString(existRegex.String(), rep.String())
232+
if err != nil {
233+
log.Errorln(err)
232234
}
235+
existRegexCheck = match
236+
}
233237

234-
// precisely mode
235-
if !flag {
236-
log.Debugf(nonExistInfo, name, site)
237-
break
238-
} else if !detectArgs.precisely {
239-
// flag=true && precisely=false
240-
log.Infof(existInfo, name, site, userPage)
241-
break
242-
} else if index == len(detectReq)-1 {
243-
// flag=true && precisely=true
244-
log.Infof(existInfo, name, site, userPage)
238+
// nonExistRegex have a veto power
239+
nonExistRegex := detectData.Get("nonExistRegex")
240+
nonExistRegexCheck := false
241+
if nonExistRegex.Exists() && len(nonExistRegex.Str) != 0 {
242+
match, err := regexp.MatchString(nonExistRegex.String(), rep.String())
243+
if err != nil {
244+
log.Errorln(err)
245245
}
246+
nonExistRegexCheck = match
247+
}
248+
if statusCodeCheck && existRegexCheck && !nonExistRegexCheck {
249+
*flag = true
246250
}
247251

252+
userPage := detectData.Get("userPage").String()
253+
if strings.Contains(userPage, "%s") {
254+
userPage = fmt.Sprintf(userPage, name)
255+
}
256+
257+
// precisely mode
258+
if !*flag {
259+
log.Debugf(nonExistInfo, name, site)
260+
return false
261+
} else if !detectArgs.precisely {
262+
// flag=true && precisely=false
263+
log.Infof(existInfo, name, site, userPage)
264+
return false
265+
} else if requestTimes == detectCount {
266+
// flag=true && precisely=true && last request
267+
log.Infof(existInfo, name, site, userPage)
268+
return true
269+
} else {
270+
return true
271+
}
248272
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func init() {
1616

1717
var rootCmd = &cobra.Command{
1818
Use: "DetectDee",
19-
Short: "Hunt down social media accounts by username across social networks && Credential Stuffing them",
19+
Short: "Hunt down social media accounts by username, email or phone across social networks && Credential Stuffing them",
2020
Long: ``,
2121
Run: func(cmd *cobra.Command, args []string) {
2222
fmt.Println(cmd.UsageString())

0 commit comments

Comments
 (0)