Skip to content

Commit

Permalink
it works
Browse files Browse the repository at this point in the history
jaspermayone committed Jul 21, 2024
1 parent 9ac6c9f commit 58dd197
Showing 5 changed files with 116 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "",
"name": "phishbot",
"version": "0.0.0",
"description": "",
"main": "index.js",
@@ -30,6 +30,7 @@
"express": "^4.19.2",
"form-data": "^4.0.0",
"js-yaml": "^4.1.0",
"moment": "^2.30.1",
"node-fetch": "2",
"node-statsd": "^0.1.1",
"nodemon": "^3.0.3",
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions src/functions/domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App } from "@slack/bolt";
import { Classification } from "../types";

let reviewChannel;
let feedChannel;
@@ -101,12 +102,19 @@ export async function sendNewDomainMessage(app: App, domain: String) {
// console.log(ts);
// console.log(domain);

let data = {
domain: domain,
ts: ts,
};

let dataString = JSON.stringify(data);
// create a function that takes in domain and ts, as well as the classification and then returns the json data
async function createData(
domain: String,
ts: String,
classification: Classification
) {
let data = {
domain: domain,
ts: ts,
classification: classification,
};
return JSON.stringify(data);
}

await app.client.chat.update({
token: process.env.SLACK_BOT_TOKEN,
@@ -151,31 +159,31 @@ export async function sendNewDomainMessage(app: App, domain: String) {
text: "Postal",
emoji: true,
},
value: `${dataString}`,
value: `${await createData(domain, ts, "postal")}`,
},
{
text: {
type: "plain_text",
text: "Banking",
emoji: true,
},
value: `${dataString}`,
value: `${await createData(domain, ts, "banking")}`,
},
{
text: {
type: "plain_text",
text: "Item Scams",
emoji: true,
},
value: `${dataString}`,
value: `${await createData(domain, ts, "item_scams")}`,
},
{
text: {
type: "plain_text",
text: "Other",
emoji: true,
},
value: `${dataString}`,
value: `${await createData(domain, ts, "other")}`,
},
],
action_id: "domain_classification",
98 changes: 87 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@ import { App, ExpressReceiver } from "@slack/bolt";
import axios from "axios";
import colors from "colors";
import express from "express";
import moment from "moment";

import { indexEndpoint } from "./endpoints";
import { healthEndpoint } from "./endpoints/health";
import { newDomainEndpoint } from "./endpoints/newDomain";
import { sendNewDomainMessage } from "./functions/domain";
import { t } from "./lib/templates";
import { blog, slog } from "./util/Logger";

type Classification = "postal" | "banking" | "item_scams" | "other";

let reviewChannel;
let feedChannel;
let reviewChannel: string;
let feedChannel: string;

if (process.env.NODE_ENV === "production") {
reviewChannel = "C07DP360WDP"; // phish-classification
@@ -58,25 +58,30 @@ app.action(/.*?/, async (args) => {

let domain = data.domain;
let ts = data.ts;

// @ts-expect-error
let classif = payload.selected_option.text.text;
classif = classif.toLowerCase();
let classification = data.classification;

await client.chat.delete({
token: process.env.SLACK_BOT_TOKEN,
channel: reviewChannel,
ts: ts,
});

let baseUrl: string;

if (process.env.NODE_ENV === "production") {
baseUrl = "https://api.phish.directory";
} else {
baseUrl = "http://localhost:3000";
}

let rsp = await axios.post(
`https://api.phish.directory/domain/verdict?key=${process.env.SECRET_KEY}&domain=${domain}&suser=${actionUser}&verdict=${classif}`
`${baseUrl}/domain/verdict?key=${process.env.SECRET_KEY}&domain=${domain}&suser=${actionUser}&verdict=${classification}`
);

let classmsg = await client.chat.postMessage({
token: process.env.SLACK_BOT_TOKEN,
channel: feedChannel,
text: `> Domain: ${domain} has been classified as ${classif} by <@${actionUser}>`,
text: `> Domain: ${domain} has been classified as ${classification} by <@${actionUser}>`,
});

let classTs = classmsg.ts;
@@ -122,7 +127,78 @@ app.action(/.*?/, async (args) => {
app.command(/.*?/, async ({ ack, body, client }) => {
try {
await ack();
// This is not used

let user = body.user_id;
let channel = body.channel_id;
let command = body.command;

switch (command) {
case "/ping":
let uptime = process.uptime();
// format the uptime
let uptimeString = new Date(uptime * 1000).toISOString().substr(11, 8);

let dateStarted = new Date(Date.now() - uptime * 1000);
// format the date started with moment
let dateStartedFormatted =
moment(dateStarted).format("MM-DD-YY H:m:s A Z");

await client.chat.postEphemeral({
token: process.env.SLACK_BOT_TOKEN,
user: user,
channel: body.channel_id,
text: `Pong! 🏓 \n\n I've been awake for ${uptimeString}, I got up at ${dateStartedFormatted}!`,
});
break;
case "/report":
let domain = body.text;

if (!domain) {
await client.chat.postEphemeral({
token: process.env.SLACK_BOT_TOKEN,
user: user,
channel: channel,
text: "Please provide a domain to report",
});
return;
}

// check if the domain is a valid domain, or if it has things like a protocol or spaces (which makes it a url)
// evalueates using this regex: ^(?!http:\/\/|https:\/\/)[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$
// if it doesn't match, then it's not a valid domain
if (
!domain.match(/^(?!http:\/\/|https:\/\/)[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/)
) {
await client.chat.postEphemeral({
token: process.env.SLACK_BOT_TOKEN,
user: user,
channel: channel,
text: "Please provide a valid domain to report",
});
return;
}

let baseUrl: string;

if (process.env.NODE_ENV === "production") {
baseUrl = "https://api.phish.directory";
} else {
baseUrl = "http://localhost:3000";
}

// fixme: once api is ready send to api

sendNewDomainMessage(app, domain).then(() => {
client.chat.postEphemeral({
token: process.env.SLACK_BOT_TOKEN,
user: user,
channel: channel,
text: `Domain ${domain} has been reported for classification. Thank you!`,
});
});

break;
}
} catch (error) {
blog(`Error in command handler: ${error}`, "error");
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Classification = "postal" | "banking" | "item_scams" | "other";

0 comments on commit 58dd197

Please sign in to comment.