Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ksp-submission
This repository is created for Karnataka State Police Hackathon 2023 - submission collection.
## Team Information
### Team Name -
### Problem Statement -
### Team Name - Anti Pirates
### Problem Statement - Fraud App Detection
1 change: 1 addition & 0 deletions Vanchan-E_ Anti_Pirates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
249 changes: 249 additions & 0 deletions Vanchan-E_ Anti_Pirates/AI caller.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 32,
"id": "cb4d1c8c",
"metadata": {},
"outputs": [],
"source": [
"#pip install azure-cognitiveservices-speech\n",
"import azure.cognitiveservices.speech as speechsdk\n",
"import time\n",
"import random"
]
},
{
"cell_type": "markdown",
"id": "f862a0f6",
"metadata": {},
"source": [
"# speech-to-text"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "b1a4e52f",
"metadata": {},
"outputs": [],
"source": [
"def recognize_from_microphone():\n",
" # This example requires environment variables named \"SPEECH_KEY\" and \"SPEECH_REGION\"\n",
" speech_config = speechsdk.SpeechConfig(subscription='e8cbc273eb1a43e7a6a38938b8a30b63', region='centralindia')\n",
" speech_config.speech_recognition_language=\"en-IN\"\n",
"\n",
" audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)\n",
" speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)\n",
"\n",
" print(\"Speak into your microphone.\")\n",
" speech_recognition_result = speech_recognizer.recognize_once_async().get()\n",
"\n",
" if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:\n",
" print(\"Recognized: {}\".format(speech_recognition_result.text))\n",
" return speech_recognition_result.text\n",
" elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:\n",
" print(\"No speech could be recognized: {}\".format(speech_recognition_result.no_match_details))\n",
" elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:\n",
" cancellation_details = speech_recognition_result.cancellation_details\n",
" print(\"Speech Recognition canceled: {}\".format(cancellation_details.reason))\n",
" if cancellation_details.reason == speechsdk.CancellationReason.Error:\n",
" print(\"Error details: {}\".format(cancellation_details.error_details))\n",
" print(\"Did you set the speech resource key and region values?\")\n",
"\n",
"# caller_text = recognize_from_microphone()"
]
},
{
"cell_type": "markdown",
"id": "f98591c0",
"metadata": {},
"source": [
"# text-to-speech"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "e7db3970",
"metadata": {},
"outputs": [],
"source": [
"def reply(input_text):\n",
" # This example requires environment variables named \"SPEECH_KEY\" and \"SPEECH_REGION\"\n",
" speech_config = speechsdk.SpeechConfig(subscription='2eac4093659042a89d98671a3bb6d341', region='centralindia')\n",
" audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)\n",
"\n",
" # The language of the voice that speaks.\n",
" speech_config.speech_synthesis_voice_name='en-IN-PrabhatNeural'\n",
"\n",
" speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)\n",
"\n",
" speech_synthesis_result = speech_synthesizer.speak_text_async(input_text).get()\n",
"\n",
" if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:\n",
" print(\"Speech synthesized for text [{}]\".format(input_text))\n",
" elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:\n",
" cancellation_details = speech_synthesis_result.cancellation_details\n",
" print(\"Speech synthesis canceled: {}\".format(cancellation_details.reason))\n",
" if cancellation_details.reason == speechsdk.CancellationReason.Error:\n",
" if cancellation_details.error_details:\n",
" print(\"Error details: {}\".format(cancellation_details.error_details))\n",
" print(\"Did you set the speech resource key and region values?\")"
]
},
{
"cell_type": "markdown",
"id": "f38edaaa",
"metadata": {},
"source": [
"# main()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "2eaea08a",
"metadata": {},
"outputs": [],
"source": [
"standard_replies = [\"i can't hear your voice, can you please be more clear ?\",\n",
" \"can you please repeat what you just said, sorry! there is some network issue here.\",\n",
" \"i didn't understand what you just said.\",\n",
" \"i want to know more.\"]\n",
"prev = \"\"\n",
"replies={\"talking\" : \"Yes, tell me\",\n",
" \"speaking\" : \"Yes, tell me\",\n",
" \"calling\" : \"Yes, go ahead\",\n",
" \"interested?\" : \"yes, i am interested\",\n",
" \"you want\" : \"yes\",\n",
" \"otp\" : \"yes, just a second, its 569434\",\n",
" \"one time passowrd\" : \"yes, just a second, its 785495\",\n",
" \"wanted loan\" : \"yes\",\n",
" \"betting\" : \" can you explain this more to me\",\n",
" \"what\": standard_replies[0],\n",
" \"hear me\": \"it is better now\",\n",
" \"details\": \"I forgot my account details, can you please tell me your address so that I can send DD to you\",\n",
" \"repeat\": prev,\n",
" \"kind\": \"As I said right, i wanted instant loan. can you please get me that?\",\n",
" \"looking\":\"i wanted instant loan. can you please get me that?\",\n",
" \"address\":\"Thank you, I'll send it to the specified address\",\n",
" \"thank\":\"Bye.\",\n",
" \"thanks\" : \"Bye\"\n",
" }"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "965a8c68",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Speak into your microphone.\n",
"Recognized: Hello, I am Vishnu. I am speaking to Mr Aniket.\n",
"Speech synthesized for text [Yes, tell me]\n",
"Speak into your microphone.\n",
"Recognized: I am from Financial Services department. I see that you registered on our website about a loan. Can we talk about this right now?\n",
"Speech synthesized for text [i want to know more.]\n",
"Speak into your microphone.\n",
"Recognized: Yeah. Which loan do you want to actually?\n",
"Speech synthesized for text [i want to know more.]\n",
"Speak into your microphone.\n",
"Recognized: What type of loan you want actually?\n",
"Speech synthesized for text [can you please repeat what you just said, sorry! there is some network issue here.]\n",
"Speak into your microphone.\n",
"Recognized: What kind of loan you want?\n",
"Speech synthesized for text [As I said right, i wanted instant loan. can you please get me that?]\n",
"Speak into your microphone.\n",
"Recognized: Yeah, sure. Can you please share me your bank details?\n",
"Speech synthesized for text [i can't hear your voice, can you please be more clear ?]\n",
"Speak into your microphone.\n",
"Recognized: Can you hear me your bank details please?\n",
"Speech synthesized for text [I forgot my account details, can you please tell me your address so that I can send DD to you]\n",
"Speak into your microphone.\n",
"Recognized: Yeah, my address is Dash Dash dash and you can send it to this address.\n",
"Speech synthesized for text [Thank you, I'll send it to the specified address]\n",
"Speak into your microphone.\n",
"Recognized: Thanks.\n",
"Speech synthesized for text [i can't hear your voice, can you please be more clear ?]\n",
"Speak into your microphone.\n",
"Recognized: Thank you.\n",
"Speech synthesized for text [i want to know more.]\n",
"Speak into your microphone.\n",
"Recognized: Fill cut that thing last.\n",
"Speech synthesized for text [i didn't understand what you just said.]\n",
"Speak into your microphone.\n",
"No speech could be recognized: NoMatchDetails(reason=NoMatchReason.NotRecognized)\n"
]
},
{
"ename": "AttributeError",
"evalue": "'NoneType' object has no attribute 'split'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[36], line 5\u001b[0m\n\u001b[0;32m 3\u001b[0m rand_idx \u001b[39m=\u001b[39m random\u001b[39m.\u001b[39mrandint(\u001b[39m0\u001b[39m, \u001b[39mlen\u001b[39m(standard_replies)\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m)\n\u001b[0;32m 4\u001b[0m caller_text \u001b[39m=\u001b[39m recognize_from_microphone()\n\u001b[1;32m----> 5\u001b[0m caller_text \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(caller_text\u001b[39m.\u001b[39;49msplit(\u001b[39m\"\u001b[39m\u001b[39m \u001b[39m\u001b[39m\"\u001b[39m))\n\u001b[0;32m 6\u001b[0m flag\u001b[39m=\u001b[39m\u001b[39m0\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[39mfor\u001b[39;00m key,value \u001b[39min\u001b[39;00m replies\u001b[39m.\u001b[39mitems():\n",
"\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'split'"
]
}
],
"source": [
"end_time = time.time() + (60*2)\n",
"while time.time() < end_time:\n",
" rand_idx = random.randint(0, len(standard_replies)-1)\n",
" caller_text = recognize_from_microphone()\n",
" caller_text = list(caller_text.split(\" \"))\n",
" flag=0\n",
" for key,value in replies.items():\n",
" if key in caller_text:\n",
" prev = key\n",
" reply(value)\n",
" flag=1\n",
" break\n",
" if flag==0:\n",
" reply(standard_replies[rand_idx])\n",
" \n",
"reply(\"ok, i will call you later, got to go, bye\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06a9b1b2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.9 64-bit (microsoft store)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
"vscode": {
"interpreter": {
"hash": "256e7590f6950b5f6dd0a496b5ee28ed8f63fc44a32891a1ff556d54add0dbb6"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Vanchan-E_ Anti_Pirates/Website_Frontend
Submodule Website_Frontend added at e07ba1
28 changes: 28 additions & 0 deletions Vanchan-E_ Anti_Pirates/blobupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobClient, BlobServiceClient, PublicAccess

account_url = "https://kspstorage1.blob.core.windows.net/"

creds = DefaultAzureCredential()
service_client = BlobServiceClient(
account_url=account_url,
credential=creds
)

container_name="sgf"
try:
new_container = service_client.create_container(container_name, public_access=PublicAccess.Container)
except Exception as e:
print(e)
new_container = service_client.get_container_client(container_name)
for blob in new_container.list_blobs():
print(blob)

blob_name = "testblob1"
blob_url = f"{account_url}/{container_name}/{blob_name}"

blob_client = BlobClient(account_url, container_name, blob_name)

with open("hist1.png", "rb") as blob_file:
blob_client.upload_blob(data=blob_file)

93 changes: 93 additions & 0 deletions Vanchan-E_ Anti_Pirates/checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import requests
import base64
import os
from bs4 import BeautifulSoup
from dotenv import load_dotenv
load_dotenv()

from sqlconnector import SqlConnector
obj = SqlConnector()

def doAppBrainRequest():
print("Performing GET request to appbrain to get the details of new apps...")
api_key = os.getenv("APP_BRAIN_API").strip()
request_headers = {'content-type': 'application/json'}
res = []
url = 'https://api.appbrain.com/v2/info/browse?apikey={}&sort=POPULAR_INDIA&filter=FREE&category=CASINO&offset=500&limit=50'.format(api_key)
app_brain_res = requests.get(url)
if app_brain_res.ok:
res.extend(app_brain_res.json()['apps'])
url = 'https://api.appbrain.com/v2/info/browse?apikey={}&sort=POPULAR_INDIA&filter=FREE&category=FINANCE&offset=500&limit=50'.format(api_key)
app_brain_res = requests.get(url)
if app_brain_res.ok:
res.extend(app_brain_res.json()['apps'])
return res


def doVTRequest(url_to_test):
req_endpoint = "https://www.virustotal.com/api/v3/urls/{}"
encoded = base64.urlsafe_b64encode(url_to_test.encode()).decode().strip("=")
req_endpoint = req_endpoint.format(encoded)
print(req_endpoint)
print(f"Sending query to VirusTotal API...")
apikey = os.getenv('VT_API')
request_headers = {"x-apikey": apikey}
vt_data = requests.get(req_endpoint, headers=request_headers)
if vt_data.ok:
return vt_data.json()
else:
return None

inplaystore = []
notinplaystore = []

def checkInPlaystore(num, package):
url = "https://play.google.com/store/apps/details?id={}".format(package.strip())
html_content = requests.get(url).text
soup = BeautifulSoup(html_content, "html.parser")
btns = soup.find_all('span')
flag = 0
for btn in btns:
if btn.text.strip().lower() == "install":
flag = 1
break
if flag:
inplaystore.append(num)
else:
notinplaystore.append(num)


def start():

result = doAppBrainRequest()

for num, app in enumerate(result):
checkInPlaystore(num, app['package'])

for app in inplaystore:
name = base64.b64encode(result[app]['name'].encode()).decode()
website = "NA" if result[app]['website']=="" else result[app]['website']
devname = "NA" if result[app]['developerName']=="" else result[app]['developerName']
query = "insert into app_list (app_name, website, developer, package_name, platform) values ('{}','{}','{}','{}','{}')".format(name, website, devname, result[app]['package'], "Android")
try:
obj.insert(query)
except:
continue
r = doVTRequest(result[app]['website'])
app_id = obj.retrieve("select id from app_list where package_name ='{}'".format(result[app]['package']))[0][0]
if r is None:
threat="Malicious/Website not there"
harmless = 0
malicious = 1

else:
threat = r['data']['attributes']['threat_names']
threat = "" if threat==[] else threat[0]
harmless = r['data']['attributes']['total_votes']['harmless'] + r['data']['attributes']['last_analysis_stats']['harmless']
malicious = harmless = r['data']['attributes']['total_votes']['malicious'] + r['data']['attributes']['last_analysis_stats']['malicious']
query = "insert into virustotal (app_id, type, count_malicious, count_non_malicious) values ('{}','{}','{}','{}')"\
.format(app_id, threat, malicious, harmless)

obj.insert(query)

start()
Binary file added Vanchan-E_ Anti_Pirates/hist1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading