Created
July 27, 2020 17:03
-
-
Save yechs/eb464d8b530286f3aa24cb3d4da4a43a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"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.8.3-final" | |
}, | |
"orig_nbformat": 2, | |
"kernelspec": { | |
"name": "python38364bited148bcd63344783a013271593cf9d24", | |
"display_name": "Python 3.8.3 64-bit" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from scapy.all import *" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"packets = rdpcap('gcloud-reply.pcap')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "<gcloud-received.pcap: TCP:0 UDP:0 ICMP:2700 Other:0>" | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
], | |
"source": [ | |
"packets" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "b'/*\\n * Copyright (c) 2013-2015 Erik Ekman <yarrick@kryo.se>\\n *\\n * Permission to use, copy, modify, and/or distribute this software for any purpose\\n * with or without fee is hereby granted, provided that the above copyright notice\\n * and this permission notice appear in all copies.\\n *\\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\\n * FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\\n * PERFORMANCE OF THIS SOFTWARE.\\n */\\n#include <stdlib.h>\\n#include <stdio.h>\\n#include <string.h>\\n#include <netdb.h>\\n#include <pwd.h>\\n\\n#include \"host.h\"\\n#include \"fs.h\"\\n#include \"net.h\"\\n#include \"chunk.h\"\\n\\n#include <arpa/inet.h>\\n\\n#define DEFAULT_TIMEOUT_S 1\\n\\nstruct ar'" | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
], | |
"source": [ | |
"packets[1000]['ICMP']['Raw'].load" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "'8.8.8.8'" | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
], | |
"source": [ | |
"packets[1000]['IP'].src" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"vocabulary = []" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for pkt in packets:\n", | |
" vocabulary.append(pkt['ICMP']['Raw'].load)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "2700" | |
}, | |
"metadata": {}, | |
"execution_count": 8 | |
} | |
], | |
"source": [ | |
"len(vocabulary)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Remove duplicates\n", | |
"vocabulary = list(dict.fromkeys(vocabulary))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "25" | |
}, | |
"metadata": {}, | |
"execution_count": 10 | |
} | |
], | |
"source": [ | |
"len(vocabulary)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 61, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# These are the files containing bytes from the image\n", | |
"image = vocabulary[4] + vocabulary[7] + vocabulary[10]+ vocabulary[13] + vocabulary[15] + vocabulary[17] + vocabulary[19] + vocabulary[20] + vocabulary[21] + vocabulary[22] + vocabulary[23] + vocabulary[24]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 62, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"with open(\"image.jpg\", \"wb\") as output:\n", | |
" output.write(image)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment