#!/usr/bin/env python3
# -*- coding:utf-8 -*-
pip install <package>
pip list
# commentaire
"""
commentaires
"""
a = "chaine de chars"
type(a)
dir(a)
help(str)
a.__len__()
a.upper()
var = input("saisie : ")
print(f"{var.__len__()} caractères saisis")
Il faut néanmoins rester prudents avec les saisies utilisateurs.
"""
== : égal à
!= : différent de
< : inférieur à
> : supérieur à
<= : inférieur ou égal à
>= : supérieur ou égal à
"""
x = 5
if x > 2:
print("x est plus grand que 2")
else:
print("x est plus petit ou égal à 2")
x = 5
y = "plus grand que 2" if x > 2 else "plus petit ou égal à 2"
for i in range(5):
print(i)
fruits = ["pomme", "banane", "cerise"]
for fruit in fruits:
print(fruit)
[print(i) for i in range(4)]
try:
1/0
except Exception as err:
print(type(err).__name__)
import time
time.ctime(152546)
#'Fri Jan 2 19:22:26 1970'
import base64
base64.b64encode(b'test')
#'dGVzdA=='
import binascii
binascii.hexlify('A')
#'41'
binascii.unhexlify('41')
#'A'
with open("nomDuFichier", 'r') as f:
line = f.readline()
while line:
print(line)
line = f.readline() #ligne suivante
import os
os.system("dir")
import subprocess
scan = subprocess.Popen(["nmap","-sP","127.0.0.1","-oG", "test" ], stdout=subprocess.PIPE)
while scan.poll() is None: #on attend la fin du process
if scan.returncode == 0:
print("[*] scan arp terminé")
python3 -m http.server
python -m SimpleHTTPServer
sudo python3 -m http.server 80
import binascii
bin(int(binascii.hexlify(b'Dojo-101'), 16))[2:]
binascii.unhexlify('%x' % int('0b' + '100010001101111011010100110111100101101001100010011000000110001', 2))
import urllib.parse
encodedStr = 'Hell%C3%B6%20W%C3%B6rld%40Python'
urllib.parse.unquote(encodedStr)
'Hellö Wörld@Python'
Connection sur la couche TCP/UDP
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('taisen.fr',443))
sock.send(b'test')
sock.recv(1024)
sock.close()
import urllib.parse
urllib.parse.quote('&')
#'%26'
import http.client
connection = http.client.HTTPSConnection("www.google.com")
connection.request("GET", "/")
response = connection.getresponse()
print("Status: {} and reason: {}".format(response.status, response.reason))
response.read()
connection.close()
conn = http.client.HTTPSConnection('enirdd6d0146.x.pipedream.net')
conn.request("POST", "/", '{ "name": "Princess Leia" }', {'Content-Type': 'application/json'})
import requests
base_url = "https://localhost:3000"
url = f"{base_url}/?lang=english"
token = "ey...................."
headers = {
"Authorization": f"Bearer {token}"
}
response = requests.get(url, headers=headers, verify=False)
# Vérification des conditions de correspondance
if response.status_code == 200 and ("success" in response.text or "16-bit" in response.text):
print("Condition matched and status is 200")
else:
print(f"Received status code: {response.status_code} with no matching content")
import requests
url = "http://localhost:4000/Login"
payload = {
"user": "user",
"passwd": "password"
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 401:
print("Unauthorized access - status code 401")
else:
print(f"Received status code: {response.status_code}")
import requests
url = "http://staging-order.mango.htb"
headers = {'Content-type': 'application/x-www-form-urlencoded'}
post_data = "username=admin&password=admin&login=login"
r = requests.post(url, data=post_data, headers=headers, allow_redirects=False)
import requests
from bs4 import BeautifulSoup
response = requests.get("http://taisen.fr")
soup = BeautifulSoup(response.text, 'html.parser')
print(soup.find('h1').text)
ord('A')
65
chr(65)
'A'
from struct import pack
pack('<I', 0x08048474)
python -c "import pty;pty.spawn('/bin/bash')"
import string
string.printable
#'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
string.ascii_letters
#'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.digits
#'0123456789'
def multipar2(i):
return i*2
multipar2(4)
if __name__ == "__main__":
pass
import threading
threading.Thread( target = <fonction>, args = [ <argument> ] ).start()