hacktricks/generic-methodologies-and-resources/python/bruteforce-hash-few-chars.md

79 lines
3.3 KiB
Markdown
Raw Normal View History

{% hint style="success" %}
Leer & oefen AWS-hacking: <img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Opleiding AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Leer & oefen GCP-hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Opleiding GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Ondersteun HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Kontroleer die [**inskrywingsplanne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking-truuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-opslag.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
```python
import hashlib
target = '2f2e2e' #/..
candidate = 0
while True:
2024-02-11 02:07:06 +00:00
plaintext = str(candidate)
hash = hashlib.md5(plaintext.encode('ascii')).hexdigest()
if hash[-1*(len(target)):] == target: #End in target
print('plaintext:"' + plaintext + '", md5:' + hash)
break
candidate = candidate + 1
```
2021-04-05 20:42:13 +00:00
```python
#From isHaacK
import hashlib
from multiprocessing import Process, Queue, cpu_count
def loose_comparison(queue, num):
2024-02-11 02:07:06 +00:00
target = '0e'
plaintext = f"a_prefix{str(num)}a_suffix"
hash = hashlib.md5(plaintext.encode('ascii')).hexdigest()
2021-04-05 20:42:13 +00:00
2024-02-11 02:07:06 +00:00
if hash[:len(target)] == target and not any(x in "abcdef" for x in hash[2:]):
print('plaintext: ' + plaintext + ', md5: ' + hash)
queue.put("done") # triggers program exit
2021-04-05 20:42:13 +00:00
def worker(queue, thread_i, threads):
2024-02-11 02:07:06 +00:00
for num in range(thread_i, 100**50, threads):
loose_comparison(queue, num)
2021-04-05 20:42:13 +00:00
def main():
2024-02-11 02:07:06 +00:00
procs = []
queue = Queue()
threads = cpu_count() # 2
2021-04-05 20:42:13 +00:00
2024-02-11 02:07:06 +00:00
for thread_i in range(threads):
proc = Process(target=worker, args=(queue, thread_i, threads ))
proc.daemon = True # kill all subprocess when main process exits.
procs.append(proc)
proc.start()
2021-04-05 20:42:13 +00:00
2024-02-11 02:07:06 +00:00
while queue.empty(): # exits when a subprocess is done
pass
return 0
2021-04-05 20:42:13 +00:00
main()
```
{% hint style="success" %}
Leer & oefen AWS-hacking: <img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Opleiding AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Leer & oefen GCP-hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Opleiding GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Ondersteun HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Kontroleer die [**inskrywingsplanne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking-truuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-opslag.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}