Skip to content

add script name_check #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 16, 2020
Merged
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
98 changes: 98 additions & 0 deletions src/scripts/osint/check_nickname/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3

import asyncio
from pathlib import Path

import aiohttp
import requests

from src.core.base.osint import OsintRunner
from src.core.utils.response import ScriptResponse


class Defaults:
NETWORKS_LIST = "social_networks.txt"


class Networks:
def __init__(self):
with open(Path("./src/scripts/osint/check_nickname/data/social_networks.txt")) as file:
self.net = file.read().splitlines()


def check_nickname_sync(nickname: str) -> list:
"""
checks nicknames from social networks(sync)
:param nickname: just nickname :)
:return: list with links to user from social
networks which have this nickname
"""
ans = []
social = Networks().net
for site in social:
try:
url = "https://{site}{nickname}".format(site=site, nickname=nickname)
response = requests.get(url)
if response.status_code == 200:
ans.append(url)
except:
pass
return ans


async def check_nickname_async(nickname: str, social) -> list:
"""
checks nicknames from social networks(async)
:param nickname: just nickname :)
:param social: social
:return: list with links to user from social
networks which have this nickname
"""
ans = []
async with aiohttp.ClientSession() as session:
while not social.empty():
url = await social.get()
try:
async with session.get(url) as response:
if response.status == 200:
ans.append(url)
except:
pass
return ans


class Runner(OsintRunner):
def __init__(self, logger: str = __name__):
super().__init__(logger=logger)

@staticmethod
async def __run(*args, **kwargs):
try:
username = kwargs.get("username")
social = asyncio.Queue()
for site in Networks().net:
await social.put(
"https://{site}{username}".format(site=site, username=username)
)
temp_result = await asyncio.gather(
*[
asyncio.create_task(check_nickname_async(username, social))
for _ in range(10)
]
)
result = {username: []}
for sub_massive in temp_result:
for site in sub_massive:
result[username].append(site)
return ScriptResponse.success(
result=result,
message="Found {count} user accounts".format(
count=len(result[username])
),
)
except Exception as err:
return ScriptResponse.error(message=str(err))

def run(self, *args, **kwargs):
username = kwargs.get("username")
return asyncio.run(self.__run(username=username))
12 changes: 12 additions & 0 deletions src/scripts/osint/check_nickname/data/social_networks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
twitter.com/
vk.com/
ok.ru/
instagram.com/
github.com/
reddit.com/user/
tiktok.com/@
mastodon.social/@
blackplanet.com/
flickr.com/photos/


10 changes: 10 additions & 0 deletions src/scripts/osint/check_nickname/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
certifi==2020.6.20
chardet==3.0.4
idna==2.10
multidict==4.7.6
requests==2.24.0
urllib3==1.25.9
yarl==1.4.2
9 changes: 5 additions & 4 deletions src/scripts/other/simple_example/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env python3

from src.core.base.osint import OsintRunner, PossibleKeys
from src.core.base.osint import BaseRunner, PossibleKeys
from src.core.utils.response import ScriptResponse
from src.core.utils.validators import validate_kwargs


class Runner(OsintRunner):
class Runner(BaseRunner):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Справедливо, но только валидатор всё равно будет валидировать OsintRunner аргументы (посмотри на строку 19 в скрипте):

    @validate_kwargs(PossibleKeys.KEYS)
    def run(self, *args, **kwargs) -> ScriptResponse.success or ScriptResponse.error:

Поэтому, если используем BaseRunner, валидатор в скрипте отключаем, если OsintRunner - то оставляем.

В данном случае, валидатор тогда нужно удалить (декоратор убрать).
Ну и раз уж simple_example поправил, то нужно и user_greeting зафиксить, убрать декоратор, пофиксить родительский класс.

"""
Basic example
"""

def __init__(self, logger: str = __name__):
"""
Re-init base class instance
Expand All @@ -25,4 +24,6 @@ def run(self, *args, **kwargs) -> ScriptResponse.success or ScriptResponse.error
:param kwargs: kwargs
:return: ScriptResponse message
"""
return ScriptResponse.success(message="Script finished")
return ScriptResponse.success(
message="Script finished"
)
Empty file added src/scripts/recon/.gitkeep
Empty file.