def ExportFile(self, findings): ct = datetime.datetime.now().strftime("%I-%M%p_%B_%d_%Y") exportfile = 'bagged_goods' + "_" + str(ct) + '.txt' with open(exportfile, 'a+') as file: bc = utilities.sbc(exportfile, findings.decode('utf-8')) if bc is None: file.write(findings + "\n")
def QueryUserDatabase(self, UNID): userdatabase = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/users/user.database' unidbool = UNID.isdigit() # smart case detection efb = os.stat(userdatabase).st_size == 0 if efb is True: utilities.pi("{} User database is currently empty!".format(FAIL)) exit(0) utilities.pi(" ") if unidbool is False: with open(userdatabase, 'r') as file: # Database item check ic = utilities.sbc(userdatabase, UNID) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace("\n", '') itemid = item.split(' - ')[1].replace("\n", '') # Link to github profile item = item.split(' - ')[0] # github username if UNID in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in database".format(FAIL, UNID)) break elif unidbool is True: with open(userdatabase, 'r') as file: # Database item check ic = utilities.sbc(userdatabase, UNID) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace("\n", '') itemid = item.split(' - ')[0].replace("\n", '') # Link to github profile item = item.split(' - ')[1] # github username if UNID in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in database".format(FAIL, UNID)) break utilities.pi(" ")
def code(self, query, listonly=False): if query == 'q': utilities.pi('{}Exiting Treasure ...'.format(notifications.INFO)) exit(0) elif query == '' or query == ' ': utilities.pi(' {} Empty code searches are not allowed.'.format(notifications.ERROR)) exit(0) utilities.pi("\n {}Hunting for {}".format(notifications.INFO, query)) page = 1 breakpoint = 1 while breakpoint == 1: params = dict( q = query, type = "Code", p = page ) r = utilities.GetHTTPostRequest(searchfor.SEARCH, params) if searchfor.is_last_page(r.content): utilities.pi('** No more results for {} **'.format(query)) breakpoint = 2 # Break the while loop. break for u in searchfor.extract(r.content): ru = searchfor.raw_url(u) if listonly: print ru else: fn = searchfor.make_fname(u) ret = utilities.GetHTTPRequest(ru) if ret.status_code == 200: codedumppath = '{}.code.dump'.format(query.replace(' ', '_')) # Print output utilities.pi(" {}".format(notifications.FOUND) + ru.split('/')[-1] + " " + "from {}".format(ru.split('/')[3])) with open(codedumppath, "a+") as file: cb = utilities.sbc(codedumppath, ret.text.encode('utf-8')) if cb is None: # Quick Fix. # If there are any unicode errors, just pass them for now. try: filecontent = ret.content.decode('utf-8').encode('utf-8') except Exception: pass file.write(filecontent + '\n') file.close() elif cb is True: pass else: pass page += 1
def QueryUserFollowingDatabase(self, username, followingname): username = username.lower() followingdatabasepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/following/{}.following'.format(username) unidbool = followingname.isdigit() # smart case detection utilities.pi(" ") if unidbool is True: with open(followingdatabasepath, 'r') as file: # Database item check ic = utilities.sbc(followingdatabasepath, followingname) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace("\n", '') itemid = item.split(' - ')[0].replace("\n", '') # Link to github profile item = item.split(' - ')[1] # github username if followingname in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in {}'s following database".format(FAIL, followingname, username)) break elif unidbool is False: with open(followingdatabasepath, 'r') as file: # Database item check ic = utilities.sbc(followingdatabasepath, followingname) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace("\n", '') itemid = item.split(' - ')[1].replace("\n", '') # Link to github profile item = item.split(' - ')[0] # github username if followingname in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in {}'s following database".format(FAIL, followingname, username)) break utilities.pi(" ")
def WriteUserToDatabaseSILENTLY(self, Username): Username = Username.lower() userdatabase = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/users/user.database' DNC = utilities.sbc(userdatabase, Username) # Database name check if DNC is True: pass IDN = regexops.GetUserID(Username) if IDN is None: utilities.pi("\n{}User doesn't exist.\n".format(ERROR, )) exit(0) databasepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/users/user.database' with open(databasepath, 'a+') as file: bc = utilities.sbc(databasepath, Username) if bc is None: #print line | for debugging rounds. file.write(Username + " - " + str(IDN) + " - " + github.domain + Username + "\n") if bc is True: pass
def QueryOrgPeopleDatabase(self, username, person): username = username.lower() orgpeoplepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/organizations/people/{}s.people'.format(username) utilities.pi(" ") puib = person.isdigit() if puib is False: with open(orgpeoplepath, 'r') as file: # Database item check ic = utilities.sbc(orgpeoplepath, person) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace('\n', '') itemid = item.split(' - ')[1].replace("\n", '') # Link to github profile item = item.split(' - ')[0] # github username if person in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in {}'s people database".format(FAIL, person, username)) break utilities.pi(" ") if puib is True: with open(orgpeoplepath, 'r') as file: # Database item check ic = utilities.sbc(orgpeoplepath, person) # Database item/name check for item in file: itemlink = item.split(' - ')[2].replace('\n', '') itemid = item.split(' - ')[0].replace("\n", '') # Link to github profile item = item.split(' - ')[1] # github username if person in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemid + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in {}'s people database".format(FAIL, person, username)) break utilities.pi(" ")
def WriteUsersReposToFile(self, Username, Repos): utilities.pi(INFO + "Collected {} of {}'s Repositories".format(len(Repos), Username)) time.sleep(3) utilities.pi(INFO + "Wrote {} of {}'s Repositories to disk\n".format(len(Repos), Username)) idwe = 'https://github.com' Username = Username.lower() repospath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/repositories/{}.repositories'.format(Username) with open(repospath, 'a+') as file: for line in Repos: line = line.lower() bc = utilities.sbc(repospath, line) if bc is None: #print line | for debugging rounds. reponame = line.split('/')[2] file.write(reponame + " - " + idwe + line + "\n")
def WriteWhoUserIsFollowingToFile(self, Username, Following): utilities.pi(INFO + "Collected {} users that {} is following".format(len(Following), Username)) time.sleep(3) utilities.pi(INFO + "Writing {} to disk".format(len(Following), Username)) Username = Username.lower() # Override any UPPERCASE strings followspath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/following/{}.following'.format(Username) with open(followspath, 'a+') as file: for line in Following: line = line.lower() bc = utilities.sbc(followspath, line) if bc is None: #print line | for debugging rounds. IDN = regexops.GetUserID(line) if IDN is None: IDN = "No Profile Traceroute." file.write(line + " - " + IDN + " - " + github.domain + line + "\n") utilities.pi(INFO + "Wrote {} to disk\n".format(len(Following), Username))
def WriteUserToDatabaseVERBALLY(self, Username): Username = Username.lower() IDN = regexops.GetUserID(Username) if IDN is None: utilities.pi("\n{}User doesn't exist.\n".format(ERROR, )) exit(0) databasepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/users/user.database' with open(databasepath, 'a+') as file: bc = utilities.sbc(databasepath, Username) if bc is None: utilities.pi('\n{}Added {} to the user database.\n'.format(INFO, Username)) #print line | for debugging rounds. file.write(Username + " - " + str(IDN) + " - " + github.domain + Username + "\n") if bc is True: utilities.pi('\n{}{} has already been added to the user database.\n'.format(INFO, Username))
def WriteOrgPeopleToFile(self, Username, people): utilities.pi(INFO + "Collected {} of {}'s people".format(len(people), Username)) time.sleep(3) utilities.pi(INFO + "Writing {} of {}'s people to disk".format(len(people), Username)) Username = Username.lower() peoplespath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/organizations/people/{}s.people'.format(Username) with open(peoplespath, 'a+') as file: for line in people: line = line.lower() bc = utilities.sbc(peoplespath, line) if bc is None: #print line | for debugging rounds. IDN = regexops.GetUserID(line) if IDN is None: IDN = "No Profile Traceroute." file.write(line + " - " + IDN + " - " + github.domain + line + "\n") utilities.pi(INFO + "Wrote {} of {}'s people to disk.\n".format(len(people), Username))
def QueryUserStarredRepoDatabase(self, username, reponame): username = username.lower() reposdatabasepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/repositories/starred/{}.starred.repos'.format(username) utilities.pi(" ") with open(reposdatabasepath, 'r') as file: # Database item check ic = utilities.sbc(reposdatabasepath, reponame) # Database item/name check for item in file: itemlink = item.split(' - ')[1].replace("\n", '') # Link to github profile item = item.split(' - ')[0] # github username if reponame in item and ic is True: utilities.pi("{}{}".format(FOUND, item + " - " + itemlink)) break if ic is None: utilities.pi("{}{} Not found in {}'s starred repositories database".format(FAIL, reponame, username)) break utilities.pi(" ")
def WriteUsersFollowersToFile(self, Username, Followers): utilities.pi(INFO + "Collected {} of {}'s followers".format(len(Followers), Username)) time.sleep(3) utilities.pi(INFO + "Writing {} of {}'s followers to disk".format(len(Followers), Username)) Username = Username.lower() #os.chdir('..') followerspath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/core/database/followers/{}.followers'.format(Username) with open(followerspath, 'a+') as file: for line in Followers: line = line.lower() bc = utilities.sbc(followerspath, line) if bc is None: #print line | for debugging rounds. IDN = regexops.GetUserID(line) if IDN is None: IDN = "No Profile Traceroute." file.write(line + " - " + IDN + " - " + github.domain + line + "\n") utilities.pi(INFO + "Wrote {} of {}'s followers to disk.\n".format(len(Followers), Username))