bug-bounty / app.py
Canstralian's picture
Update app.py
e10fcb1 verified
import streamlit as st
from requests_html import HTMLSession
import pandas as pd
import langchain as lc
import openai
import os
# Set your OpenAI API key (ensure it's set securely in production)
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
st.title("Cybersecurity Vulnerability Scanner & AI Analyzer")
# Initialize variables
links = []
js_files = []
forms = []
# Input URL for scraping
url = st.text_input("Enter the target URL:")
if st.button("Scrape and Scan"):
if url:
st.write(f"Processing {url}...")
# Initialize an HTML session
session = HTMLSession()
response = session.get(url)
# Attempt to render JavaScript content, if necessary
try:
response.html.render()
except Exception as e:
st.warning(f"JavaScript rendering failed: {e}")
# Extract links, JavaScript files, and forms from the page
links = [link.attrs['href'] for link in response.html.find('a') if 'href' in link.attrs]
js_files = [script.attrs['src'] for script in response.html.find('script') if 'src' in script.attrs]
forms = [form.attrs.get('action', 'No action') for form in response.html.find('form')]
# Display extracted data
st.success("Scraping and scanning complete!")
st.write("Links:", links)
st.write("JavaScript Files:", js_files)
st.write("Forms:", forms)
else:
st.warning("Please enter a valid URL.")
# AI-based analysis section
user_prompt = st.text_area("Enter an AI prompt for analysis:")
if st.button("Analyze with AI"):
if user_prompt:
# Initialize LangChain with OpenAI LLM for AI analysis
llm = lc.LLMChain(llm=lc.OpenAI())
full_prompt = f"{user_prompt}\nLinks:\n{links}\nJS Files:\n{js_files}\nForms:\n{forms}"
# Run the AI analysis
try:
ai_analysis = llm.run(full_prompt)
st.write("AI Analysis:")
st.write(ai_analysis)
except Exception as e:
st.error(f"AI analysis failed: {e}")
else:
st.warning("Please provide an AI prompt for analysis.")