Anonymous Anonymous - 19 days ago
54 0

No description

Python

sitecheck

def sucuri_sitecheck(self, keyword, keyword_type):   # Khang
        '''
        Harvests data from sitecheck.sucuri.net
        Takes an IP or domain

        Notes: 
        * IP's have to be translatable into a domain name
        * Has a paid API
        '''
        query_data = ['Sucuri SiteCheck']
        info_dict = {}
        url = 'https://sitecheck.sucuri.net/results/' + keyword
        query_data.append(url)

        try:
            uClient = urlopen(url)
            info = uClient.read()
            uClient.close()
        
            soup = BeautifulSoup(info, "html.parser")
            contain = soup.find("div", {"class" : "tab-content results"})
            sub_contain = contain.findAll("div", {"class" : "panel-body"})
            sub_contain_title = contain.findAll("h4", {"class" : "panel-title"})

            for i in range(0, len(sub_contain)):
                title = re.sub('\n', '', sub_contain_title[i].text)
                temp_str = []
                nrof_Block = 0
                malicious_entries = 0
                if title != "Blacklist Status":
                    text = str(sub_contain[i].text).split("\n")
                    for data in text:
                        if data != '' and data != 'System Details:' and data != 'Web application details:' :
                            temp_str.append((data, False))
                            nrof_Block += 1
                    info_dict[title] = (temp_str, 0, nrof_Block)

                else:
                    text_blue = sub_contain[i].findAll("td", {"class" : "scan-blue"})
                    text_red = sub_contain[i].findAll("td", {"class" : "scan-red"})
                    for data in text_red:
                        temp_str.append((data.text, True))
                        nrof_Block += 1
                        malicious_entries += 1
                    for data in text_blue:
                        temp_str.append((data.text, False))
                        nrof_Block += 1
                    info_dict[title] = (temp_str, malicious_entries, nrof_Block)

            sub_contain = contain.find("table", {"class" : "table main-result"}).findAll("td")
            temp_str = []
            nrof_Block = 0
            malicious_entries = 0
            malicious_key = ['harmful', 'required', 'blocking', 'security']
            for i in range(int(len(sub_contain) / 2)):

                malicious = False
                for mal in malicious_key:
                    if mal in str(sub_contain[i*2 + 1].text).lower():
                        malicious = True
                        malicious_entries += 1
                        break

                temp_str.append((str(sub_contain[i*2].text + ' ' + sub_contain[i*2 + 1].text), malicious))
                nrof_Block += 1
            info_dict['Result'] = (temp_str, malicious_entries, nrof_Block)

            sub_contain = contain.find("table", {"class" : "table scan-findings"}).findAll("td")
            temp_str = []
            nrof_Block = 0
            malicious_entries = 0
            malicious_key = ['critical', 'medium']
            for i in range(int(len(sub_contain) / 4)):

                malicious = False
                for mal in malicious_key:
                    if mal in str(sub_contain[i*4 + 2].text).lower():
                        malicious = True
                        malicious_entries += 1
                        break

                temp_str.append(('Scan: ' + sub_contain[i*4].text, malicious))
                temp_str.append(('Result: ' + sub_contain[i*4 + 1].text, malicious))
                temp_str.append(('Severity: ' + sub_contain[i*4 + 2].text, malicious))
                temp_str.append(('Recommendation: ' + sub_contain[i*4 + 3].text, malicious))
                temp_str.append(('----------------------------------------------------', False)) 
                nrof_Block += 1
            if temp_str:
                temp_str.pop()
            info_dict['Scans'] = (temp_str, malicious_entries, nrof_Block)

            query_data.append(info_dict)

        except Exception:
            query_data.append({})

        return query_data