mirror of
https://github.com/carlospolop/hacktricks
synced 2024-12-21 18:43:29 +00:00
99 lines
4.4 KiB
Markdown
99 lines
4.4 KiB
Markdown
# Integer Overflow
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* Você trabalha em uma **empresa de segurança cibernética**? Você quer ver sua **empresa anunciada no HackTricks**? ou você quer ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF**? Verifique os [**PLANOS DE ASSINATURA**](https://github.com/sponsors/carlospolop)!
|
|
* Descubra [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nossa coleção exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Adquira o [**swag oficial do PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Junte-se ao** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo telegram**](https://t.me/peass) ou **siga-me** no **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Compartilhe seus truques de hacking enviando PRs para o** [**repositório hacktricks**](https://github.com/carlospolop/hacktricks) **e** [**repositório hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|
|
|
|
{% tabs %}
|
|
{% tab title="Rust" %}
|
|
```rust
|
|
fn main() {
|
|
|
|
let mut quantity = 2147483647;
|
|
|
|
let (mul_result, _) = i32::overflowing_mul(32767, quantity);
|
|
let (add_result, _) = i32::overflowing_add(1, quantity);
|
|
|
|
println!("{}", mul_result);
|
|
println!("{}", add_result);
|
|
}
|
|
```
|
|
{% endtab %}
|
|
|
|
{% tab title="Python" %}
|
|
### Python
|
|
|
|
```python
|
|
import struct
|
|
|
|
def pack_signed_int(i):
|
|
return struct.pack("<i", i)
|
|
|
|
def pack_unsigned_int(i):
|
|
return struct.pack("<I", i)
|
|
|
|
def unpack_signed_int(b):
|
|
return struct.unpack("<i", b)[0]
|
|
|
|
def unpack_unsigned_int(b):
|
|
return struct.unpack("<I", b)[0]
|
|
```
|
|
|
|
#### Example
|
|
|
|
```python
|
|
>>> pack_signed_int(-2147483648)
|
|
b'\x00\x00\x00\x80'
|
|
>>> unpack_signed_int(b'\x00\x00\x00\x80')
|
|
-2147483648
|
|
>>> pack_unsigned_int(4294967295)
|
|
b'\xff\xff\xff\xff'
|
|
>>> unpack_unsigned_int(b'\xff\xff\xff\xff')
|
|
4294967295
|
|
```
|
|
|
|
#### References
|
|
|
|
* [Python struct documentation](https://docs.python.org/3/library/struct.html)
|
|
|
|
````
|
|
```c
|
|
#include <stdio.h>
|
|
#include <limits.h>
|
|
|
|
int main() {
|
|
int a = INT_MAX;
|
|
int b = 0;
|
|
int c = 0;
|
|
|
|
b = a * 100;
|
|
c = a + 1;
|
|
|
|
printf("%d\n", INT_MAX);
|
|
printf("%d\n", b);
|
|
printf("%d\n", c);
|
|
return 0;
|
|
}
|
|
````
|
|
{% endtab %}
|
|
{% endtabs %}
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* Você trabalha em uma **empresa de segurança cibernética**? Você quer ver sua **empresa anunciada no HackTricks**? ou você quer ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF**? Confira os [**PLANOS DE ASSINATURA**](https://github.com/sponsors/carlospolop)!
|
|
* Descubra [**A Família PEASS**](https://opensea.io/collection/the-peass-family), nossa coleção exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Adquira o [**swag oficial do PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* **Junte-se ao** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo do Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo do telegram**](https://t.me/peass) ou **siga-me** no **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Compartilhe seus truques de hacking enviando PRs para o** [**repositório hacktricks**](https://github.com/carlospolop/hacktricks) **e** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|