From 700948593990726225d61f7396287fbcda6cb478 Mon Sep 17 00:00:00 2001 From: GOUNTANTE yendoukoa <134739293+GYFX35@users.noreply.github.com> Date: Fri, 19 Jul 2024 21:24:14 +0000 Subject: [PATCH 1/9] Create generator-generic-ossf-slsa3-publish.yml --- .../generator-generic-ossf-slsa3-publish.yml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/generator-generic-ossf-slsa3-publish.yml diff --git a/.github/workflows/generator-generic-ossf-slsa3-publish.yml b/.github/workflows/generator-generic-ossf-slsa3-publish.yml new file mode 100644 index 000000000000..35c829b139b5 --- /dev/null +++ b/.github/workflows/generator-generic-ossf-slsa3-publish.yml @@ -0,0 +1,66 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow lets you generate SLSA provenance file for your project. +# The generation satisfies level 3 for the provenance requirements - see https://slsa.dev/spec/v0.1/requirements +# The project is an initiative of the OpenSSF (openssf.org) and is developed at +# https://github.com/slsa-framework/slsa-github-generator. +# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier. +# For more information about SLSA and how it improves the supply-chain, visit slsa.dev. + +name: SLSA generic generator +on: + workflow_dispatch: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + outputs: + digests: ${{ steps.hash.outputs.digests }} + + steps: + - uses: actions/checkout@v4 + + # ======================================================== + # + # Step 1: Build your artifacts. + # + # ======================================================== + - name: Build artifacts + run: | + # These are some amazing artifacts. + echo "artifact1" > artifact1 + echo "artifact2" > artifact2 + + # ======================================================== + # + # Step 2: Add a step to generate the provenance subjects + # as shown below. Update the sha256 sum arguments + # to include all binaries that you generate + # provenance for. + # + # ======================================================== + - name: Generate subject for provenance + id: hash + run: | + set -euo pipefail + + # List the artifacts the provenance will refer to. + files=$(ls artifact*) + # Generate the subjects (base64 encoded). + echo "hashes=$(sha256sum $files | base64 -w0)" >> "${GITHUB_OUTPUT}" + + provenance: + needs: [build] + permissions: + actions: read # To read the workflow path. + id-token: write # To sign the provenance. + contents: write # To add assets to a release. + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.4.0 + with: + base64-subjects: "${{ needs.build.outputs.digests }}" + upload-assets: true # Optional: Upload to a new release From 66ffc55701c21a4b634906e6daef4fa90483bb3a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:46:50 +0000 Subject: [PATCH 2/9] feat: Initial version of the Scam Detection AI --- collections/scam-detection-ai/app.py | 56 ++++++++++++ .../scam-detection-ai/email_analyzer.py | 86 +++++++++++++++++++ .../scam-detection-ai/email_fetcher.py | 76 ++++++++++++++++ collections/scam-detection-ai/index.md | 8 ++ .../scam-detection-ai/templates/index.html | 38 ++++++++ .../scam-detection-ai/templates/result.html | 27 ++++++ .../templates/results_list.html | 35 ++++++++ .../scam-detection-ai/test_email_analyzer.py | 44 ++++++++++ 8 files changed, 370 insertions(+) create mode 100644 collections/scam-detection-ai/app.py create mode 100644 collections/scam-detection-ai/email_analyzer.py create mode 100644 collections/scam-detection-ai/email_fetcher.py create mode 100644 collections/scam-detection-ai/index.md create mode 100644 collections/scam-detection-ai/templates/index.html create mode 100644 collections/scam-detection-ai/templates/result.html create mode 100644 collections/scam-detection-ai/templates/results_list.html create mode 100644 collections/scam-detection-ai/test_email_analyzer.py diff --git a/collections/scam-detection-ai/app.py b/collections/scam-detection-ai/app.py new file mode 100644 index 000000000000..21309b7f062c --- /dev/null +++ b/collections/scam-detection-ai/app.py @@ -0,0 +1,56 @@ +from flask import Flask, render_template, request +from email_analyzer import analyze_email +from email_fetcher import fetch_emails + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/analyze', methods=['POST']) +def analyze(): + if 'email_text' in request.form: + email_text = request.form['email_text'] + analysis = analyze_email(email_text) + total_score = sum(analysis.values()) + is_scam = total_score >= 3 + return render_template('result.html', analysis=analysis, is_scam=is_scam) + + elif 'fetch_emails' in request.form: + username = request.form['username'] + password = request.form['password'] + emails = fetch_emails(username, password) + + analyzed_emails = [] + if emails: + for email_message in emails: + body = "" + if email_message.is_multipart(): + for part in email_message.walk(): + if part.get_content_type() == "text/plain": + body = part.get_payload(decode=True).decode() + break + else: + body = email_message.get_payload(decode=True).decode() + + analysis = analyze_email(body) + total_score = sum(analysis.values()) + is_scam = total_score >= 3 + + subject, _ = email.header.decode_header(email_message["Subject"])[0] + if isinstance(subject, bytes): + subject = subject.decode() + + analyzed_emails.append({ + "subject": subject, + "from": email_message['From'], + "analysis": analysis, + "is_scam": is_scam + }) + return render_template('results_list.html', emails=analyzed_emails) + + return "Invalid request", 400 + +if __name__ == '__main__': + app.run(debug=True) diff --git a/collections/scam-detection-ai/email_analyzer.py b/collections/scam-detection-ai/email_analyzer.py new file mode 100644 index 000000000000..634e303c26f9 --- /dev/null +++ b/collections/scam-detection-ai/email_analyzer.py @@ -0,0 +1,86 @@ +import re + +def analyze_email(email_text): + """ + Analyzes an email for potential scam indicators. + + Args: + email_text: The full text of the email. + + Returns: + A dictionary containing the analysis results. + """ + scam_indicators = { + "urgency": 0, + "generic_greeting": 0, + "suspicious_links": 0, + "unusual_sender": 0, + "payment_requests": 0, + "attachments": 0 + } + + # Urgency keywords + urgency_keywords = ["urgent", "immediate", "action required", "limited time", "expire"] + for keyword in urgency_keywords: + if re.search(r'\b' + keyword + r'\b', email_text, re.IGNORECASE): + scam_indicators["urgency"] = 1 + break + + # Generic greeting + generic_greetings = ["dear customer", "dear user", "sir/madam"] + for greeting in generic_greetings: + if email_text.lower().startswith(greeting): + scam_indicators["generic_greeting"] = 1 + break + + # Suspicious links (basic check for non-standard URLs) + if re.search(r'http[s]?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/[a-zA-Z0-9_.-]+', email_text): + scam_indicators["suspicious_links"] = 1 + + # Unusual sender (very basic check) + if "From:" in email_text: + from_line = email_text.split("From:")[1].split("\n")[0] + if re.search(r'<.*@.*>', from_line) and not re.search(r'<.*@.*\..*>', from_line): + scam_indicators["unusual_sender"] = 1 + + # Payment requests + payment_keywords = ["payment", "invoice", "wire transfer", "bank account", "credit card"] + for keyword in payment_keywords: + if re.search(r'\b' + keyword + r'\b', email_text, re.IGNORECASE): + scam_indicators["payment_requests"] = 1 + break + + # Attachments + if "Content-Disposition: attachment" in email_text: + scam_indicators["attachments"] = 1 + + return scam_indicators + +if __name__ == '__main__': + sample_email = """ + From: Suspicious Sender + Subject: Urgent Action Required: Your Account Will Be Deactivated + + Dear user, + + We have detected suspicious activity on your account. For your security, we have temporarily suspended your account. + To reactivate your account, you must verify your identity by clicking the link below and updating your payment information. + + http://suspicious-link.com/verify + + Failure to do so within 24 hours will result in permanent account deactivation. + + Thank you for your cooperation. + + Sincerely, + The Security Team + """ + + analysis = analyze_email(sample_email) + print(analysis) + + total_score = sum(analysis.values()) + if total_score >= 3: + print("\nThis email is likely a scam!") + else: + print("\nThis email seems legitimate.") diff --git a/collections/scam-detection-ai/email_fetcher.py b/collections/scam-detection-ai/email_fetcher.py new file mode 100644 index 000000000000..4430bef5d003 --- /dev/null +++ b/collections/scam-detection-ai/email_fetcher.py @@ -0,0 +1,76 @@ +import imaplib +import email +from email.header import decode_header + +def fetch_emails(username, password, server="imap.gmail.com"): + """ + Fetches emails from an IMAP server. + + Args: + username: The email account username. + password: The email account password. + server: The IMAP server address. + + Returns: + A list of email messages. + """ + try: + # connect to the server + mail = imaplib.IMAP4_SSL(server) + # login + mail.login(username, password) + # select the inbox + mail.select("inbox") + + # search for all emails + status, messages = mail.search(None, "ALL") + email_ids = messages[0].split() + + emails = [] + for email_id in email_ids[-5:]: # Fetch last 5 emails for demonstration + status, msg_data = mail.fetch(email_id, "(RFC822)") + for response_part in msg_data: + if isinstance(response_part, tuple): + msg = email.message_from_bytes(response_part[1]) + emails.append(msg) + + mail.logout() + return emails + + except imaplib.IMAP4.error as e: + print(f"IMAP Error: {e}") + return [] + +if __name__ == '__main__': + # This is a placeholder for a secure way to get credentials + EMAIL_USERNAME = "your_email@gmail.com" + EMAIL_PASSWORD = "your_app_password" + + emails = fetch_emails(EMAIL_USERNAME, EMAIL_PASSWORD) + if emails: + for email_message in emails: + subject, encoding = decode_header(email_message["Subject"])[0] + if isinstance(subject, bytes): + subject = subject.decode(encoding if encoding else "utf-8") + + print("="*50) + print(f"Subject: {subject}") + print(f"From: {email_message['From']}") + print(f"To: {email_message['To']}") + + if email_message.is_multipart(): + for part in email_message.walk(): + content_type = part.get_content_type() + content_disposition = str(part.get("Content-Disposition")) + try: + body = part.get_payload(decode=True).decode() + if "attachment" not in content_disposition: + print("\n--- Body ---\n", body) + except: + pass + else: + body = email_message.get_payload(decode=True).decode() + print("\n--- Body ---\n", body) + print("="*50 + "\n") + else: + print("Could not fetch emails. Please check your credentials and IMAP settings.") diff --git a/collections/scam-detection-ai/index.md b/collections/scam-detection-ai/index.md new file mode 100644 index 000000000000..06f6f71f6824 --- /dev/null +++ b/collections/scam-detection-ai/index.md @@ -0,0 +1,8 @@ +--- +title: "Scam Detection AI" +layout: collection +permalink: /collection/scam-detection-ai/ +collection: scam-detection-ai +--- + +This collection contains the source code for the Scam Detection AI, a project that aims to detect and prevent scams from various sources like emails, SMS, and fake news. diff --git a/collections/scam-detection-ai/templates/index.html b/collections/scam-detection-ai/templates/index.html new file mode 100644 index 000000000000..7907ee82663c --- /dev/null +++ b/collections/scam-detection-ai/templates/index.html @@ -0,0 +1,38 @@ + + + + + + Scam Detection AI + + + +
+

Scam Detection AI

+ +

Analyze Email Text

+
+ +

+ +
+ +
+

Fetch and Analyze Emails from Your Inbox

+
+ +
+

+
+

+ +
+
+
+ + diff --git a/collections/scam-detection-ai/templates/result.html b/collections/scam-detection-ai/templates/result.html new file mode 100644 index 000000000000..e96fc5b92030 --- /dev/null +++ b/collections/scam-detection-ai/templates/result.html @@ -0,0 +1,27 @@ + + + + + + Analysis Result + + + +

Analysis Result

+
+

{{ 'This email is likely a scam!' if is_scam else 'This email seems legitimate.' }}

+ +
+
+ Analyze another email + + diff --git a/collections/scam-detection-ai/templates/results_list.html b/collections/scam-detection-ai/templates/results_list.html new file mode 100644 index 000000000000..a77ddf097c82 --- /dev/null +++ b/collections/scam-detection-ai/templates/results_list.html @@ -0,0 +1,35 @@ + + + + + + Fetched Email Analysis + + + +

Fetched Email Analysis

+ {% if emails %} + {% for email in emails %} +
+

Subject: {{ email.subject }}

+

From: {{ email.from }}

+

{{ 'This email is likely a scam!' if email.is_scam else 'This email seems legitimate.' }}

+ +
+ {% endfor %} + {% else %} +

Could not fetch or analyze emails. Please check your credentials and try again.

+ {% endif %} +
+ Back to Home + + diff --git a/collections/scam-detection-ai/test_email_analyzer.py b/collections/scam-detection-ai/test_email_analyzer.py new file mode 100644 index 000000000000..9aa3013b5729 --- /dev/null +++ b/collections/scam-detection-ai/test_email_analyzer.py @@ -0,0 +1,44 @@ +import unittest +from email_analyzer import analyze_email + +class TestEmailAnalyzer(unittest.TestCase): + + def test_scam_email(self): + scam_email = """ + From: Urgent Winner + Subject: Action Required: You have won a prize! + + Dear customer, + + You have won a lottery! To claim your prize, please send your bank account details and a payment of $50 for processing fees. + Click this link to proceed: http://fake-prize.com/claim + + This is a limited time offer, it will expire in 24 hours. + """ + analysis = analyze_email(scam_email) + self.assertEqual(analysis['urgency'], 1) + self.assertEqual(analysis['generic_greeting'], 1) + self.assertEqual(analysis['suspicious_links'], 1) + self.assertEqual(analysis['payment_requests'], 1) + + def test_legitimate_email(self): + legitimate_email = """ + From: John Doe + Subject: Project Update + + Hi Team, + + Here is the update on our project. I've attached the weekly report. + Let's discuss it in our meeting tomorrow. + + Best, + John + """ + analysis = analyze_email(legitimate_email) + self.assertEqual(analysis['urgency'], 0) + self.assertEqual(analysis['generic_greeting'], 0) + self.assertEqual(analysis['suspicious_links'], 0) + self.assertEqual(analysis['payment_requests'], 0) + +if __name__ == '__main__': + unittest.main() From 33007ae122ad0e1f87f9df67ceb68953111cb88e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:48:31 +0000 Subject: [PATCH 3/9] feat: Initial version of the Scam Detection AI --- .../__pycache__/email_analyzer.cpython-312.pyc | Bin 0 -> 2926 bytes collections/scam-detection-ai/email_analyzer.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc diff --git a/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc b/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f9c471c6c43ee25f28dfbdfbc413d4e515c0694e GIT binary patch literal 2926 zcmcgtO>7&-6`tkaF8?garY!#^lh(0KStMQ8P-{W3qr`FIHi!^Qh8jgKG1?u8Bkd0} zvn!bl1*kxPsz8A%rx-yGMo$iWNr3`QfTFzy$VIdqm|pkLpeNrHyQiM|W_KytLIL;G zk+hokX5Rn2?|qZcXArE?Uq7mKVE0c+bXOwUJpBwdpCSVpiiu{C5&Ia;Dl}%qmrofZmm(YAYcR->AcT%H5XX{p6Xbx#!3 zPy&wnET^FqwZ~G&yLx0jP^iK;4u4Ot#RA_IqxTd0eQHfvL`M7%%37=yyNqs}M`$hX z?#eHL%-&@rTJa_@jfDKRkh^xZ1FE%pCWt$|*ajr~Es zLSGI@eoL7`#X|F|42Csf6SL8z0uviki!c)}I2_j78H#b1FR31@qD#m(QY@@>P#7Qd@8M{qT=+rdJm^r7j5j{lXJAv z!r$lFp74lS71TB;_xtOlVL^~pPCxXhaD|^Gu1oZqWQtZj<3Aq)F zS1e)>iznf3^QSe}t$!eHTpFuXJ|Ly$L}~VH=|Z`51&UU8UCoB37n8@rs?VgcOB%@cbW z6J2*a+ihlb2$i{5C*0tgwDa;CP$o!I=`s^_M=)8vG2BZZmz@cQVjPkpAb7pzXRf~W z?&P&M-LzoGnxE;tAiqz(xN7gk`TbFqtIM>p>TpB&YP9nQ_SRka z+U^rbFF-P6@oBHtT@^xxA)k_5|2|(K^?F5jOp^xn6&2}2$)IjXmk6tb9tQ8RNqM>6 z@beK-4UYKBpizRRxDKUXM>_{mVX$-TxcohGRDOpJeVmA=is-6;-lOy0WM&YgUi8`x1%;lz_1 zI(!*~2Okw)-OxJO1DnkUL#Nt9r?!WR_p-&#xgT##ZXGMPbCpnH@Z`U8NXz`X@vFwx zz&l?r-B;i5lq(y3TZe|*+L@gc()u=s+v>4S;iU(K6Yau@+cVpR(jC$+oPAIjZ5Kwr zaJLKNU%uBaT-r!?eVx61_f>$F&F16|oC!Cp$K$i^7cwRh+XW9W+>N@w_`G};j1@MDc03{b1;VCm9Z0XHB zz^=*k1jnAFOHOPqo8d4qNJy^kY3TA9sp(tCB+9=GP?dh5XEE%Sp zUO^^x#{to29h_pePB}FjBVoc|Fil12#?zEo0r#=&;pXwobPc9X(AgL^CR+wMOoDOv z%Jav9QVVX-MSwv_2rU=Wd;pXLh#;SJTY#%(ez5n$3&pYb= cO>$2idZ^{M_LaZYD&KWCJ3m2*BY_Y90d8R|fB*mh literal 0 HcmV?d00001 diff --git a/collections/scam-detection-ai/email_analyzer.py b/collections/scam-detection-ai/email_analyzer.py index 634e303c26f9..82e47cdca7cc 100644 --- a/collections/scam-detection-ai/email_analyzer.py +++ b/collections/scam-detection-ai/email_analyzer.py @@ -29,7 +29,7 @@ def analyze_email(email_text): # Generic greeting generic_greetings = ["dear customer", "dear user", "sir/madam"] for greeting in generic_greetings: - if email_text.lower().startswith(greeting): + if greeting in email_text.lower(): scam_indicators["generic_greeting"] = 1 break From 064cc2c5409bda3fea48547fd22064d68817bc24 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:50:54 +0000 Subject: [PATCH 4/9] feat: Add domain analysis to scam detection AI --- .../scam-detection-ai/email_analyzer.py | 23 ++++++++++++++++++- .../scam-detection-ai/templates/result.html | 12 +++++++++- .../templates/results_list.html | 12 +++++++++- .../scam-detection-ai/test_email_analyzer.py | 1 + 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/collections/scam-detection-ai/email_analyzer.py b/collections/scam-detection-ai/email_analyzer.py index 82e47cdca7cc..cfed604df07f 100644 --- a/collections/scam-detection-ai/email_analyzer.py +++ b/collections/scam-detection-ai/email_analyzer.py @@ -1,5 +1,17 @@ import re +import requests + +def get_domain_reputation(domain): + """ + Checks the reputation of a domain using a mock API. + In a real application, this would integrate with a service like VirusTotal. + """ + # This is a mock response. + if "fake" in domain or "suspicious" in domain: + return "Malicious" + return "Clean" + def analyze_email(email_text): """ Analyzes an email for potential scam indicators. @@ -16,7 +28,8 @@ def analyze_email(email_text): "suspicious_links": 0, "unusual_sender": 0, "payment_requests": 0, - "attachments": 0 + "attachments": 0, + "domain_analysis": {} } # Urgency keywords @@ -54,6 +67,14 @@ def analyze_email(email_text): if "Content-Disposition: attachment" in email_text: scam_indicators["attachments"] = 1 + # Domain analysis + urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', email_text) + domains = [re.search(r'//(.*?)/', url).group(1) for url in urls if re.search(r'//(.*?)/', url)] + + for domain in domains: + reputation = get_domain_reputation(domain) + scam_indicators["domain_analysis"][domain] = reputation + return scam_indicators if __name__ == '__main__': diff --git a/collections/scam-detection-ai/templates/result.html b/collections/scam-detection-ai/templates/result.html index e96fc5b92030..4b9d24b9419f 100644 --- a/collections/scam-detection-ai/templates/result.html +++ b/collections/scam-detection-ai/templates/result.html @@ -17,9 +17,19 @@

Analysis Result

{{ 'This email is likely a scam!' if is_scam else 'This email seems legitimate.' }}

    {% for indicator, value in analysis.items() %} -
  • {{ indicator.replace('_', ' ')|title }}: {{ 'Detected' if value else 'Not Detected' }}
  • + {% if indicator != 'domain_analysis' %} +
  • {{ indicator.replace('_', ' ')|title }}: {{ 'Detected' if value else 'Not Detected' }}
  • + {% endif %} {% endfor %}
+ {% if analysis.domain_analysis %} +

Domain Analysis

+
    + {% for domain, status in analysis.domain_analysis.items() %} +
  • {{ domain }}: {{ status }}
  • + {% endfor %} +
+ {% endif %}
Analyze another email diff --git a/collections/scam-detection-ai/templates/results_list.html b/collections/scam-detection-ai/templates/results_list.html index a77ddf097c82..2b6e229da92c 100644 --- a/collections/scam-detection-ai/templates/results_list.html +++ b/collections/scam-detection-ai/templates/results_list.html @@ -21,9 +21,19 @@

Subject: {{ email.subject }}

{{ 'This email is likely a scam!' if email.is_scam else 'This email seems legitimate.' }}

    {% for indicator, value in email.analysis.items() %} -
  • {{ indicator.replace('_', ' ')|title }}: {{ 'Detected' if value else 'Not Detected' }}
  • + {% if indicator != 'domain_analysis' %} +
  • {{ indicator.replace('_', ' ')|title }}: {{ 'Detected' if value else 'Not Detected' }}
  • + {% endif %} {% endfor %}
+ {% if email.analysis.domain_analysis %} +

Domain Analysis

+
    + {% for domain, status in email.analysis.domain_analysis.items() %} +
  • {{ domain }}: {{ status }}
  • + {% endfor %} +
+ {% endif %} {% endfor %} {% else %} diff --git a/collections/scam-detection-ai/test_email_analyzer.py b/collections/scam-detection-ai/test_email_analyzer.py index 9aa3013b5729..4301ed83fec8 100644 --- a/collections/scam-detection-ai/test_email_analyzer.py +++ b/collections/scam-detection-ai/test_email_analyzer.py @@ -20,6 +20,7 @@ def test_scam_email(self): self.assertEqual(analysis['generic_greeting'], 1) self.assertEqual(analysis['suspicious_links'], 1) self.assertEqual(analysis['payment_requests'], 1) + self.assertEqual(analysis['domain_analysis']['fake-prize.com'], 'Malicious') def test_legitimate_email(self): legitimate_email = """ From 92a45bce8e58f51622794321b5fe3793da69271c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:52:36 +0000 Subject: [PATCH 5/9] feat: Add domain analysis to scam detection AI --- .../email_analyzer.cpython-312.pyc | Bin 2926 -> 3852 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc b/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc index f9c471c6c43ee25f28dfbdfbc413d4e515c0694e..0f8450a6b46454d6e4b8f87bc08474e858def48c 100644 GIT binary patch delta 1354 zcmY*YO>7%Q6rR~1d;Po3kL@&W%cA}eCvlt>Q9%^N&5siG00b2Qa%`f-J8?GN*k*Q} z$Yw3)z#)}_LbL~ZpaLNdLA@a5(r`gYLDGdU?bS|-X>U|Aq6Q|L#fsqr?A3&j8crk0KoZ(dB*@ngjkqIVF1`FHqjE&IfZfF6j#^^7vrm+cqJI)^CX+sC1ajQl+;UQ zLpIc6K`PEkvZNFjWwjucb+wQKbFrAsOQX|w2bzI*3qVmKYm!_lX==6^*AGIfE-e?! znj)zMgXE}e5NTO8=D}MhbV0u|eX!2M)Gq?8paVY=f}e(W z-H`{wo40qPH}}QveP8<#ETaFVPXL02c{B~^r0?uek-~iLuHhU~*spMnF_{UJ*>dAJ zGh&=pV4>MCj_lb`I!*M*sSAvnURP)w6rWZC90#%O}~kiu#*(iHw?HI;gE^%!Co-T znr9isBGv6?kw>jDb{o5`f7$c}TRcv&T#&Vju3GPMQ#fdS!S!L$dcuw13znC^hTE(J zKZe^a%3sfQfO>U$-Y`ltdL}uPNc1F!X5@HvG@iy@BS;vRk6_(+ZBNMMYwgqqmJ$a0r{g1uKSRbit#I;f(3@;Xy qvPMSe5O7Yz>k9w}EXMeEZfME?itXHj|p delta 430 zcmeB?dnd+snwOW00SI*WRcGAbn#d>NH4Dg_&XB^8!kEJl#gM|(!Vtxn%9O&Kt--)h zWS_zk#mvNz%9zT$nh~Urfgy?o$Y)Juf$b;_w6sT?V+*)c$^oFHW> zYzSqQj9?LVWRXfnO^%l!Q~i>m#)CKv>_E&6#Giwhz>Z@~K|rQCY?~{XY?#<;7=sx! zMJ8`!J;=y5xq>Zb@>4c9MwZDs?Ana1lOx#efTGjcRT$YP?_qah1Lr3eGe+qT1&ouo@&&Uf03`rY?pNRd From 6d886728d54575e428c9af7a69cf32f40447e71d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:55:22 +0000 Subject: [PATCH 6/9] feat: Add SMS and message analysis to scam detection AI --- collections/scam-detection-ai/app.py | 10 ++- .../scam-detection-ai/message_analyzer.py | 63 +++++++++++++++++++ .../scam-detection-ai/templates/index.html | 9 +++ .../scam-detection-ai/templates/result.html | 6 +- .../test_message_analyzer.py | 20 ++++++ 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 collections/scam-detection-ai/message_analyzer.py create mode 100644 collections/scam-detection-ai/test_message_analyzer.py diff --git a/collections/scam-detection-ai/app.py b/collections/scam-detection-ai/app.py index 21309b7f062c..90845051323d 100644 --- a/collections/scam-detection-ai/app.py +++ b/collections/scam-detection-ai/app.py @@ -1,6 +1,7 @@ from flask import Flask, render_template, request from email_analyzer import analyze_email from email_fetcher import fetch_emails +from message_analyzer import analyze_message app = Flask(__name__) @@ -15,7 +16,14 @@ def analyze(): analysis = analyze_email(email_text) total_score = sum(analysis.values()) is_scam = total_score >= 3 - return render_template('result.html', analysis=analysis, is_scam=is_scam) + return render_template('result.html', analysis=analysis, is_scam=is_scam, analysis_type='Email') + + elif 'message_text' in request.form: + message_text = request.form['message_text'] + analysis = analyze_message(message_text) + total_score = sum(analysis.values()) + is_scam = total_score >= 2 + return render_template('result.html', analysis=analysis, is_scam=is_scam, analysis_type='Message') elif 'fetch_emails' in request.form: username = request.form['username'] diff --git a/collections/scam-detection-ai/message_analyzer.py b/collections/scam-detection-ai/message_analyzer.py new file mode 100644 index 000000000000..5c2c56912dae --- /dev/null +++ b/collections/scam-detection-ai/message_analyzer.py @@ -0,0 +1,63 @@ +import re + +def analyze_message(message_text): + """ + Analyzes an SMS or other short message for potential scam indicators. + + Args: + message_text: The full text of the message. + + Returns: + A dictionary containing the analysis results. + """ + scam_indicators = { + "shortened_urls": 0, + "unusual_sender": 0, + "urgent_requests": 0, + "prize_offers": 0 + } + + # Check for shortened URLs + shortened_url_patterns = [r'bit\.ly', r't\.co', r'goo\.gl', r'tinyurl\.com'] + for pattern in shortened_url_patterns: + if re.search(pattern, message_text): + scam_indicators["shortened_urls"] = 1 + break + + # Check for unusual sender (e.g., non-numeric sender ID) + # This is a very basic check and would need to be improved. + sender_match = re.search(r'From:\s*(\S+)', message_text, re.IGNORECASE) + if sender_match: + sender = sender_match.group(1) + if not sender.isdigit() and len(sender) > 10: + scam_indicators["unusual_sender"] = 1 + + # Check for urgent requests + urgent_keywords = ["urgent", "verify", "confirm", "login", "account"] + for keyword in urgent_keywords: + if re.search(r'\b' + keyword + r'\b', message_text, re.IGNORECASE): + scam_indicators["urgent_requests"] = 1 + break + + # Check for prize offers + prize_keywords = ["congratulations", "winner", "prize", "claim", "won"] + for keyword in prize_keywords: + if re.search(r'\b' + keyword + r'\b', message_text, re.IGNORECASE): + scam_indicators["prize_offers"] = 1 + break + + return scam_indicators + +if __name__ == '__main__': + sample_message = """ + From: 555-123-4567 + Congratulations! You've won a $1000 gift card. Click here to claim: http://bit.ly/fake-prize + """ + analysis = analyze_message(sample_message) + print(analysis) + + total_score = sum(analysis.values()) + if total_score >= 2: + print("\nThis message is likely a scam!") + else: + print("\nThis message seems legitimate.") diff --git a/collections/scam-detection-ai/templates/index.html b/collections/scam-detection-ai/templates/index.html index 7907ee82663c..20e26603effa 100644 --- a/collections/scam-detection-ai/templates/index.html +++ b/collections/scam-detection-ai/templates/index.html @@ -22,6 +22,15 @@

Analyze Email Text

+
+ +

Analyze SMS/Message Text

+
+ +

+ +
+

Fetch and Analyze Emails from Your Inbox

diff --git a/collections/scam-detection-ai/templates/result.html b/collections/scam-detection-ai/templates/result.html index 4b9d24b9419f..9e181daccb3c 100644 --- a/collections/scam-detection-ai/templates/result.html +++ b/collections/scam-detection-ai/templates/result.html @@ -12,9 +12,9 @@ -

Analysis Result

+

{{ analysis_type }} Analysis Result

-

{{ 'This email is likely a scam!' if is_scam else 'This email seems legitimate.' }}

+

{{ 'This ' + analysis_type.lower() + ' is likely a scam!' if is_scam else 'This ' + analysis_type.lower() + ' seems legitimate.' }}

    {% for indicator, value in analysis.items() %} {% if indicator != 'domain_analysis' %} @@ -32,6 +32,6 @@

    Domain Analysis

    {% endif %}

- Analyze another email + Analyze another message or email diff --git a/collections/scam-detection-ai/test_message_analyzer.py b/collections/scam-detection-ai/test_message_analyzer.py new file mode 100644 index 000000000000..c008dcb09145 --- /dev/null +++ b/collections/scam-detection-ai/test_message_analyzer.py @@ -0,0 +1,20 @@ +import unittest +from message_analyzer import analyze_message + +class TestMessageAnalyzer(unittest.TestCase): + + def test_scam_message(self): + scam_message = "Congratulations! You've won a prize. Click http://bit.ly/scam to claim." + analysis = analyze_message(scam_message) + self.assertEqual(analysis['shortened_urls'], 1) + self.assertEqual(analysis['prize_offers'], 1) + + def test_legitimate_message(self): + legitimate_message = "Your appointment is confirmed for 3 PM tomorrow." + analysis = analyze_message(legitimate_message) + self.assertEqual(analysis['shortened_urls'], 0) + self.assertEqual(analysis['prize_offers'], 0) + self.assertEqual(analysis['urgent_requests'], 0) + +if __name__ == '__main__': + unittest.main() From ca92faf35ec6cb06e7b5653d361c109fe4ab25f6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:56:49 +0000 Subject: [PATCH 7/9] feat: Add SMS and message analysis to scam detection AI --- .../email_analyzer.cpython-312.pyc | Bin 3852 -> 3852 bytes .../message_analyzer.cpython-312.pyc | Bin 0 -> 2213 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 collections/scam-detection-ai/__pycache__/message_analyzer.cpython-312.pyc diff --git a/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc b/collections/scam-detection-ai/__pycache__/email_analyzer.cpython-312.pyc index 0f8450a6b46454d6e4b8f87bc08474e858def48c..b1678f403efc28d7c7c1d168651b001d25051e23 100644 GIT binary patch delta 19 ZcmeB?>yhI+&CAQh00bfjHgYlX0{|>f1MUC- delta 19 ZcmeB?>yhI+&CAQh00f%*H*zuY0{|?@1Ofm6 diff --git a/collections/scam-detection-ai/__pycache__/message_analyzer.cpython-312.pyc b/collections/scam-detection-ai/__pycache__/message_analyzer.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ecd7faf2a6b3ec80b7a1698f543f491415ad7dff GIT binary patch literal 2213 zcmcIkO>7fK6rQ#B$A5_l386`#SqLpLU^}4+RU*_X4fKbfL?u+HQP6hrj_pm>yYB2P z)UJbk;1Hxrz=^2p0ku6)<62145pQ1XO9*TO(%?&;E)HiEy5;&AzI+kbOo0<2% zH{W}2er{=rAQ&A#eVOkJA@m1R{J}Sc=U;qm&ZtMSvp z0Kyy&E^!TuX&!U|^S;g@&_&G8#(md2-=(JLpPdfjkS5H{fafstqKW9*}GoPT*# zf)%vXT(`Nex;4JSX~JnZ#vzmA(Z5@3Vg=D{m$N>r+bakyu}ERe^A(;9Rrpz{q3@ox zZ8qnHiZC1Az1NU^Chc|_^>-_R&y^<4odHe-FZK|N9asnh3t~kC7KQ*_dc{2=6{!q% zT7=F2^-jQ7+QW?Q@CC>*Kn_(xfIR%aBeyh=E8G;~5t|dO<<*D`W6V^IQW@K_YRXd= zr(}!B7R_TK+j)ynxqxk3&0#qU>qU!Vlj^D=+ZnYW>!zk>RB91B6=}F4IeXNTnB%6U zLh%=LRKA=CAC6(jOqH#y3>f~AruijI9b)eCFeU>4)h$ycB{^f6RMk!0%z36N3)|Lh znPA&7D1^W;39HZq@3wluV-stNLk!z(bxg;0R70_`sbS*A9g>5qCfbEJmbkl^$1usxn$QY_#aDz82ldw)nh;D#jSG2K8GI=-h(FYTgm(GrlO`Uax z9I>3DE9thT=XB}@4QwXDZftjc+&IgqvXfD_^92T#qDm=-+Y$+{94zaVPU^mo!r`kUjLX|=DRoA6ARLB z(Uvw7S^*7oLtSc~twbMyAiU*f&rk3ST@JOAV1)gwc@d~S(o z|2eKYxzT=j2lYr<%~+SlssC=5G+$m z_Ud$0&Qn?(O{bx&psCVXbq*)Jdhh@?S=W|(BbW2g&&@>2AR77{HcEiOYT?k!2W*TB za0Ww7>rjL^l?am#aO9N$yPK&Nu%f_QpcaY-_AA5<`A>(}OC~gg?G&InRRf*^H%cwa z-ieGw@DGT*!5sE^WSuTpnq%O1$N;FU@$G9c)q@Y;W^Wla5Ta(ZB?z@}6Z{4%jI*+dH?XRA%Nqg_AtJ41UP|I@b Rz|+v+Ghe88A->y-;U5loMT-Cc literal 0 HcmV?d00001 From cf76bf058c013ff73af34750f622cc599d004be6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 19 Jul 2025 16:00:45 +0000 Subject: [PATCH 8/9] feat: Add PWA and Chrome extension to scam detection AI --- .../chrome-extension/background.js | 27 +++++++++++++++++ .../chrome-extension/manifest.json | 16 ++++++++++ .../chrome-extension/popup.html | 17 +++++++++++ .../chrome-extension/popup.js | 27 +++++++++++++++++ collections/scam-detection-ai/static/app.js | 2 ++ .../scam-detection-ai/static/manifest.json | 20 +++++++++++++ .../scam-detection-ai/static/styles.css | 4 +++ collections/scam-detection-ai/static/sw.js | 29 +++++++++++++++++++ .../scam-detection-ai/templates/index.html | 13 +++++++++ 9 files changed, 155 insertions(+) create mode 100644 collections/scam-detection-ai/chrome-extension/background.js create mode 100644 collections/scam-detection-ai/chrome-extension/manifest.json create mode 100644 collections/scam-detection-ai/chrome-extension/popup.html create mode 100644 collections/scam-detection-ai/chrome-extension/popup.js create mode 100644 collections/scam-detection-ai/static/app.js create mode 100644 collections/scam-detection-ai/static/manifest.json create mode 100644 collections/scam-detection-ai/static/styles.css create mode 100644 collections/scam-detection-ai/static/sw.js diff --git a/collections/scam-detection-ai/chrome-extension/background.js b/collections/scam-detection-ai/chrome-extension/background.js new file mode 100644 index 000000000000..c365c6ca8dca --- /dev/null +++ b/collections/scam-detection-ai/chrome-extension/background.js @@ -0,0 +1,27 @@ +chrome.runtime.onInstalled.addListener(() => { + chrome.contextMenus.create({ + id: "analyzeText", + title: "Analyze for Scams", + contexts: ["selection"] + }); +}); + +chrome.contextMenus.onClicked.addListener((info, tab) => { + if (info.menuItemId === "analyzeText") { + fetch('http://localhost:5000/analyze', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `message_text=${encodeURIComponent(info.selectionText)}` + }) + .then(response => response.text()) + .then(data => { + chrome.storage.local.set({ analysisResult: data }); + }) + .catch(error => { + console.error('Error:', error); + chrome.storage.local.set({ analysisResult: 'Error analyzing text.' }); + }); + } +}); diff --git a/collections/scam-detection-ai/chrome-extension/manifest.json b/collections/scam-detection-ai/chrome-extension/manifest.json new file mode 100644 index 000000000000..946ddd0b94bb --- /dev/null +++ b/collections/scam-detection-ai/chrome-extension/manifest.json @@ -0,0 +1,16 @@ +{ + "manifest_version": 3, + "name": "Scam Detection AI", + "version": "1.0", + "description": "Analyzes selected text for scams.", + "permissions": [ + "activeTab", + "contextMenus" + ], + "background": { + "service_worker": "background.js" + }, + "action": { + "default_popup": "popup.html" + } +} diff --git a/collections/scam-detection-ai/chrome-extension/popup.html b/collections/scam-detection-ai/chrome-extension/popup.html new file mode 100644 index 000000000000..49ef9d1b7dd8 --- /dev/null +++ b/collections/scam-detection-ai/chrome-extension/popup.html @@ -0,0 +1,17 @@ + + + + Scam Detection AI + + + +

Scam Detection AI

+ + +
+ + + diff --git a/collections/scam-detection-ai/chrome-extension/popup.js b/collections/scam-detection-ai/chrome-extension/popup.js new file mode 100644 index 000000000000..68d231561d8d --- /dev/null +++ b/collections/scam-detection-ai/chrome-extension/popup.js @@ -0,0 +1,27 @@ +document.addEventListener('DOMContentLoaded', () => { + chrome.storage.local.get(['analysisResult'], (result) => { + if (result.analysisResult) { + document.getElementById('result').innerHTML = result.analysisResult; + chrome.storage.local.remove(['analysisResult']); + } + }); +}); + +document.getElementById('analyzeButton').addEventListener('click', () => { + const text = document.getElementById('textToAnalyze').value; + fetch('http://localhost:5000/analyze', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `message_text=${encodeURIComponent(text)}` + }) + .then(response => response.text()) + .then(data => { + document.getElementById('result').innerHTML = data; + }) + .catch(error => { + console.error('Error:', error); + document.getElementById('result').innerText = 'Error analyzing text.'; + }); +}); diff --git a/collections/scam-detection-ai/static/app.js b/collections/scam-detection-ai/static/app.js new file mode 100644 index 000000000000..35d26bd44897 --- /dev/null +++ b/collections/scam-detection-ai/static/app.js @@ -0,0 +1,2 @@ +// This is a placeholder for your PWA's javascript. +console.log("Scam Detection AI PWA is running."); diff --git a/collections/scam-detection-ai/static/manifest.json b/collections/scam-detection-ai/static/manifest.json new file mode 100644 index 000000000000..5cc27d451507 --- /dev/null +++ b/collections/scam-detection-ai/static/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "Scam Detection AI", + "short_name": "Scam AI", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#000000", + "icons": [ + { + "src": "images/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "images/icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} diff --git a/collections/scam-detection-ai/static/styles.css b/collections/scam-detection-ai/static/styles.css new file mode 100644 index 000000000000..317bd3ce55dc --- /dev/null +++ b/collections/scam-detection-ai/static/styles.css @@ -0,0 +1,4 @@ +/* This is a placeholder for your PWA's styles. */ +body { + background-color: #f0f0f0; +} diff --git a/collections/scam-detection-ai/static/sw.js b/collections/scam-detection-ai/static/sw.js new file mode 100644 index 000000000000..58d566bcef63 --- /dev/null +++ b/collections/scam-detection-ai/static/sw.js @@ -0,0 +1,29 @@ +const CACHE_NAME = 'scam-detection-ai-cache-v1'; +const urlsToCache = [ + '/', + '/static/styles.css', // Assuming you'll have a stylesheet + '/static/app.js' // Assuming you'll have some javascript +]; + +self.addEventListener('install', event => { + event.waitUntil( + caches.open(CACHE_NAME) + .then(cache => { + console.log('Opened cache'); + return cache.addAll(urlsToCache); + }) + ); +}); + +self.addEventListener('fetch', event => { + event.respondWith( + caches.match(event.request) + .then(response => { + if (response) { + return response; + } + return fetch(event.request); + } + ) + ); +}); diff --git a/collections/scam-detection-ai/templates/index.html b/collections/scam-detection-ai/templates/index.html index 20e26603effa..2ecab4ec6ff4 100644 --- a/collections/scam-detection-ai/templates/index.html +++ b/collections/scam-detection-ai/templates/index.html @@ -4,6 +4,19 @@ Scam Detection AI + + +