Skip to content
Snippets Groups Projects
Commit 6ea5c3ad authored by Gayan Rathnathilake's avatar Gayan Rathnathilake
Browse files

Shodan-update commit-1

parent 397edd4e
No related tags found
No related merge requests found
No preview for this file type
import shodan
def shodan_scan(api_key, ips):
api = shodan.Shodan(api_key)
scan_results = []
for ip in ips:
try:
# Host information
host_info = api.host(ip)
# Append scan results to the list
scan_results.append({
scan_result = {
'ip_address': ip,
'open_ports': [{
'port': port_info['port'],
'protocol': port_info['_shodan']['module'],
'banner': port_info.get('banner', None)
} for port_info in host_info['data']],
'banner': port_info.get('banner', '')
} for port_info in host_info.get('data', []) if isinstance(port_info, dict)],
'geolocation': {
'country': host_info.get('country_name', None),
'city': host_info.get('city', None),
'latitude': host_info.get('latitude', None),
'longitude': host_info.get('longitude', None)
'country': host_info.get('country_name', 'Unknown'),
'city': host_info.get('city', 'Unknown'),
'latitude': host_info.get('latitude', 0),
'longitude': host_info.get('longitude', 0)
},
'vulnerabilities': [{
'vuln': host_info['vulns'][vuln]['summary']
} for vuln in host_info.get('vulns', {})]
'vulnerabilities': []
}
vulns_info = host_info.get('vulns', [])
if isinstance(vulns_info, list):
for cve in vulns_info:
if isinstance(cve, str):
scan_result['vulnerabilities'].append({
'cve': cve,
'summary': 'Details not provided by Shodan' # Placeholder text
})
else:
print(f"Unexpected format for vulnerability detail: {cve}")
else:
print(f"Vulnerabilities data is not in expected list format: {type(vulns_info)}")
scan_results.append(scan_result)
except shodan.APIError as e:
print(f"Error: {e}")
print(f"Error scanning IP {ip}: {e}")
except KeyError as ke:
print(f"Key error: {ke} - Possible incorrect data structure access.")
return scan_results
\ No newline at end of file
......@@ -8,7 +8,6 @@ import {
CForm,
CFormInput,
CInputGroup,
CInputGroupText,
CRow,
} from '@coreui/react'
import CIcon from '@coreui/icons-react'
......@@ -19,7 +18,6 @@ const ShodanScanner = () => {
const [scanResults, setScanResults] = useState([])
const handleAddIpAddress = () => setIpAddresses([...ipAddresses, { address: '' }])
const handleRemoveIpAddress = (index) => {
const newIpAddresses = [...ipAddresses]
newIpAddresses.splice(index, 1)
......@@ -37,8 +35,6 @@ const ShodanScanner = () => {
})
const data = await response.json()
// Log or process the scan results from the backend
console.log('Scan results:', data)
setScanResults(data.scan_results)
} catch (error) {
......@@ -108,10 +104,16 @@ const ShodanScanner = () => {
</div>
<div>
<h5>Vulnerabilities</h5>
{result.vulnerabilities &&
result.vulnerabilities.map((vuln, vulnIndex) => (
{result.vulnerabilities.map((vuln, vulnIndex) => (
<p key={vulnIndex}>
{Object.keys(vuln)[0]}: {Object.values(vuln)[0]}
<a
href={`https://nvd.nist.gov/vuln/detail/${vuln.cve}`}
target="_blank"
rel="noopener noreferrer"
>
{vuln.cve}
</a>
{vuln.cve}: {vuln.summary} (CVSS: {vuln.cvss || 'N/A'})
</p>
))}
</div>
......
......
......@@ -54,6 +54,11 @@ const WidgetsDropdown = () => {
window.location.href = '/breaches-emails#/add'
}
const handleshodanscanClick = () => {
//Change window location to '/shodan scan'
window.location.href = '/#/scan'
}
return (
<CRow>
<CCol sm={6} lg={3}>
......@@ -75,85 +80,37 @@ const WidgetsDropdown = () => {
}
/>
</CCol>
<CCol sm={6} lg={3}>
<CCol sm={6} lg={3} style={{ marginTop: '26px' }}>
<CWidgetStatsA
className="mb-4"
className="mb-4 text-center"
color="info"
value={
<>
$6.200{' '}
<span className="fs-6 fw-normal">
(40.9% <CIcon icon={cilArrowTop} />)
</span>
</>
}
title="Income"
style={{ height: '100px' }}
title={<h4 className="font-weight-bold"> Shodan Scan</h4>}
action={
<CDropdown alignment="end">
<CDropdownToggle color="transparent" caret={false} className="p-0">
<CIcon icon={cilOptions} className="text-high-emphasis-inverse" />
</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem>Action</CDropdownItem>
<CDropdownItem>Another action</CDropdownItem>
<CDropdownItem>Something else here...</CDropdownItem>
<CDropdownItem disabled>Disabled action</CDropdownItem>
<CDropdownMenu style={{ width: '80px' }}>
<CDropdownItem onClick={handleshodanscanClick}>Scan now</CDropdownItem>
</CDropdownMenu>
</CDropdown>
}
chart={
<CChartLine
className="mt-3 mx-3"
style={{ height: '70px' }}
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: 'My First dataset',
backgroundColor: 'transparent',
borderColor: 'rgba(255,255,255,.55)',
pointBackgroundColor: getStyle('--cui-info'),
data: [1, 18, 9, 17, 34, 22, 11],
},
],
}}
style={{ height: '100px' }}
options={{
plugins: {
legend: {
display: false,
},
},
maintainAspectRatio: false,
scales: {
x: {
grid: {
display: false,
drawBorder: false,
},
ticks: {
display: false,
},
},
y: {
min: -9,
max: 39,
display: false,
grid: {
display: false,
},
ticks: {
display: false,
},
},
},
elements: {
line: {
borderWidth: 1,
},
point: {
radius: 4,
hitRadius: 10,
hoverRadius: 4,
radius: 2,
hitRadius: 5,
hoverRadius: 2,
},
},
}}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment