mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-27 07:01:09 +00:00
100 lines
4.3 KiB
Markdown
100 lines
4.3 KiB
Markdown
|
# Desbordamiento de enteros
|
||
|
|
||
|
<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>
|
||
|
|
||
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
* Obtén el [**swag oficial de PEASS y HackTricks**](https://peass.creator-spring.com)
|
||
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
|
* **Comparte tus trucos de hacking enviando PR al [repositorio de hacktricks](https://github.com/carlospolop/hacktricks) y al [repositorio de 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(-1)
|
||
|
b'\xff\xff\xff\xff'
|
||
|
>>> unpack_signed_int(b'\xff\xff\xff\xff')
|
||
|
-1
|
||
|
>>> pack_unsigned_int(0xdeadbeef)
|
||
|
b'\xef\xbe\xad\xde'
|
||
|
>>> unpack_unsigned_int(b'\xef\xbe\xad\xde')
|
||
|
3735928559
|
||
|
```
|
||
|
|
||
|
### 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>
|
||
|
|
||
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
* Obtén la [**oficial PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
||
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) **grupo de Discord** o al [**grupo de telegram**](https://t.me/peass) o **sígueme en Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
||
|
* **Comparte tus trucos de hacking enviando PRs al [repositorio de hacktricks](https://github.com/carlospolop/hacktricks) y al [repositorio de hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
|
||
|
|
||
|
</details>
|