From 887030ec8d1f6bbfd9ab66fd18da2579b6b1f9ec Mon Sep 17 00:00:00 2001 From: Muhammad Daffa Date: Mon, 14 Aug 2023 12:36:19 +0700 Subject: [PATCH] feat: change it into CLI --- Dockerfile | 9 +++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++- index.php | 35 -------------------------------- main.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 36 deletions(-) create mode 100644 Dockerfile delete mode 100644 index.php create mode 100644 main.php diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a02bdf6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM php:8.0-cli + +WORKDIR /app + +COPY main.php . + +RUN apt-get update && apt-get install -y dnsutils + +CMD ["php", "main.php"] \ No newline at end of file diff --git a/README.md b/README.md index 40cc1e4..a00ea16 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,46 @@ # MailSpoof -Simple API to scans SPF, DMARC, DKIM records for issues that could allow email spoofing. +MailSpoof is a simple program that scans SPF and DMARC records for issues that could allow email spoofing. + +## Getting Started + +Follow these steps to use the MailSpoof tool using Docker: + +### Prerequisites + +- Docker installed on your system + +### Usage + +1. Clone this repository: + + +``` +git clone https://github.com/yourusername/YourRepositoryName.git +cd YourRepositoryName +``` + +2. Build the Docker image: + +``` +docker build -t mailspoof . +``` + +3. Run the Docker container and specify the target URL (replace `` with the actual URL): + +``` +docker run --rm mailspoof [--output=json] +``` + +Replace `` with the target URL you want to check. You can also include the `--output=json` flag if you want JSON output. + +4. Access the output: + +To access the output, copy the `output.txt` file from the container to your host system: + +``` +docker cp :/app/output.txt ./output.txt +``` + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 2a0e9e9..0000000 --- a/index.php +++ /dev/null @@ -1,35 +0,0 @@ -$status, - 'data'=>$data, - 'message'=>$msg - ]); -} diff --git a/main.php b/main.php new file mode 100644 index 0000000..6c80724 --- /dev/null +++ b/main.php @@ -0,0 +1,58 @@ + [--output=json]\n"; + exit(1); +} + +$url = $argv[1]; +$outputFormat = in_array('--output=json', $argv) ? 'json' : 'text'; +$results = []; + +check($url, "v=spf1"); +check("_dmarc." . $url, "v=DMARC1"); + +if ($outputFormat === 'json') { + echo json_encode($results, JSON_PRETTY_PRINT) . PHP_EOL; +} else { + displayTextOutput(); +} + +function check($url, $string) { + global $results; + + $txtRecords = dns_get_record($url, DNS_TXT); + $status = "fail"; + $data = ""; + + foreach ($txtRecords as $txtRecord) { + if (preg_match("/{$string}/i", $txtRecord['txt'])) { + $status = "success"; + $data = $txtRecord['txt']; + break; + } + } + + $recordType = ($string === "v=spf1") ? "SPF" : "DMARC"; + + $results[] = [ + 'type' => $recordType, + 'status' => $status, + 'data' => $data + ]; +} + +function displayTextOutput() { + global $results; + + foreach ($results as $result) { + echo "{$result['type']} Records:\n"; + + if ($result['type'] === 'DMARC' && $result['status'] === 'fail') { + echo "Not Found\n"; + } else { + echo "{$result['data']}\n"; + } + + echo "\n"; + } +}