New antiphish, faster yachts sink
This commit is contained in:
parent
23dc1e7de2
commit
7ecc217a92
1 changed files with 50 additions and 41 deletions
|
@ -81,6 +81,7 @@ class Jarvis(StatsClient):
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.phishing_domains = []
|
self.phishing_domains = []
|
||||||
self.pre_run_callback = self._prerun
|
self.pre_run_callback = self._prerun
|
||||||
|
self.synced = False
|
||||||
|
|
||||||
async def _chunk_all(self) -> None:
|
async def _chunk_all(self) -> None:
|
||||||
"""Chunk all guilds."""
|
"""Chunk all guilds."""
|
||||||
|
@ -88,15 +89,17 @@ class Jarvis(StatsClient):
|
||||||
self.logger.debug(f"Chunking guild {guild.name} <{guild.id}>")
|
self.logger.debug(f"Chunking guild {guild.name} <{guild.id}>")
|
||||||
await guild.chunk_guild()
|
await guild.chunk_guild()
|
||||||
|
|
||||||
@Task.create(IntervalTrigger(hours=1))
|
@Task.create(IntervalTrigger(minutes=1))
|
||||||
async def _update_domains(self) -> None:
|
async def _update_domains(self) -> None:
|
||||||
self.logger.debug("Updating phishing domains")
|
self.logger.debug("Updating phishing domains")
|
||||||
async with ClientSession(headers={"X-Identity": "Discord: zevaryx#5779"}) as session:
|
async with ClientSession(headers={"X-Identity": "Discord: zevaryx#5779"}) as session:
|
||||||
response = await session.get("https://phish.sinking.yachts/v2/recent/3700")
|
response = await session.get("https://phish.sinking.yachts/v2/recent/60")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
|
||||||
self.logger.debug(f"Found {len(data)} changes to phishing domains")
|
self.logger.debug(f"Found {len(data)} changes to phishing domains")
|
||||||
|
if len(data) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
add = 0
|
add = 0
|
||||||
sub = 0
|
sub = 0
|
||||||
|
@ -141,9 +144,11 @@ class Jarvis(StatsClient):
|
||||||
async def on_ready(self) -> None:
|
async def on_ready(self) -> None:
|
||||||
"""NAFF on_ready override."""
|
"""NAFF on_ready override."""
|
||||||
try:
|
try:
|
||||||
await self._sync_domains()
|
if not self.synced:
|
||||||
self._update_domains.start()
|
await self._sync_domains()
|
||||||
asyncio.create_task(self._chunk_all())
|
self._update_domains.start()
|
||||||
|
asyncio.create_task(self._chunk_all())
|
||||||
|
self.synced = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Failed to load anti-phishing", exc_info=e)
|
self.logger.error("Failed to load anti-phishing", exc_info=e)
|
||||||
self.logger.info("Logged in as {}".format(self.user)) # noqa: T001
|
self.logger.info("Logged in as {}".format(self.user)) # noqa: T001
|
||||||
|
@ -662,46 +667,50 @@ class Jarvis(StatsClient):
|
||||||
"""Check if the message contains any known phishing domains."""
|
"""Check if the message contains any known phishing domains."""
|
||||||
for match in url.finditer(message.content):
|
for match in url.finditer(message.content):
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
resp = await session.get(
|
resp = await session.post(
|
||||||
"https://spoopy.oceanlord.me/api/check_website", json={"website": match.string}
|
"https://anti-fish.bitflow.dev/check",
|
||||||
|
json={"message": match.string},
|
||||||
|
headers={
|
||||||
|
"Application-Name": "JARVIS",
|
||||||
|
"Application-Link": "https://git.zevaryx.com/stark-industries/jarvis",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
break
|
break
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
for item in data["processed"]["urls"].values():
|
if data["match"]:
|
||||||
if not item["safe"]:
|
self.logger.debug(
|
||||||
self.logger.debug(
|
f"Scam url `{match.string}` detected in {message.guild.id}/{message.channel.id}/{message.id}"
|
||||||
f"Scam url `{match.string}` detected in {message.guild.id}/{message.channel.id}/{message.id}"
|
)
|
||||||
)
|
expires_at = datetime.now(tz=timezone.utc) + timedelta(hours=24)
|
||||||
expires_at = datetime.now(tz=timezone.utc) + timedelta(hours=24)
|
await Warning(
|
||||||
await Warning(
|
active=True,
|
||||||
active=True,
|
admin=self.user.id,
|
||||||
admin=self.user.id,
|
duration=24,
|
||||||
duration=24,
|
expires_at=expires_at,
|
||||||
expires_at=expires_at,
|
guild=message.guild.id,
|
||||||
guild=message.guild.id,
|
reason="Unsafe URL",
|
||||||
reason="Unsafe URL",
|
user=message.author.id,
|
||||||
user=message.author.id,
|
).commit()
|
||||||
).commit()
|
tracker = warnings_tracker.labels(
|
||||||
tracker = warnings_tracker.labels(
|
guild_id=message.guild.id, guild_name=message.guild.name
|
||||||
guild_id=message.guild.id, guild_name=message.guild.name
|
)
|
||||||
)
|
tracker.inc()
|
||||||
tracker.inc()
|
reasons = ", ".join(f"{m['source']}: {m['type']}" for m in data["matches"])
|
||||||
reasons = ", ".join(item["not_safe_reasons"])
|
embed = warning_embed(message.author, reasons)
|
||||||
embed = warning_embed(message.author, reasons)
|
try:
|
||||||
try:
|
await message.channel.send(embeds=embed)
|
||||||
await message.channel.send(embeds=embed)
|
except Exception:
|
||||||
except Exception:
|
self.logger.warn("Failed to send warning embed")
|
||||||
self.logger.warn("Failed to send warning embed")
|
try:
|
||||||
try:
|
await message.delete()
|
||||||
await message.delete()
|
except Exception:
|
||||||
except Exception:
|
self.logger.warn("Failed to delete malicious message")
|
||||||
self.logger.warn("Failed to delete malicious message")
|
tracker = malicious_tracker.labels(
|
||||||
tracker = malicious_tracker.labels(
|
guild_id=message.guild.id, guild_name=message.guild.name
|
||||||
guild_id=message.guild.id, guild_name=message.guild.name
|
)
|
||||||
)
|
tracker.inc()
|
||||||
tracker.inc()
|
return True
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@listen()
|
@listen()
|
||||||
|
|
Loading…
Add table
Reference in a new issue