@@ -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
4041func 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
5657var 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}
0 commit comments