2024-07-26 17:33:17 +03:00
|
|
|
import requests
|
2024-07-28 11:12:44 +03:00
|
|
|
import secrets
|
|
|
|
import base64
|
|
|
|
import tempfile
|
2024-07-26 17:33:17 +03:00
|
|
|
import socket
|
2024-07-28 11:12:44 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
from cpaste import publish_to_cpaste
|
2024-07-26 17:33:17 +03:00
|
|
|
|
|
|
|
def publish_to_termbin(content):
|
|
|
|
host = 'termbin.com'
|
|
|
|
port = 9999
|
|
|
|
try:
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
sock.connect((host, port))
|
|
|
|
sock.sendall(content.encode('utf-8'))
|
|
|
|
response = sock.recv(1024).decode('utf-8').strip()
|
|
|
|
sock.close()
|
|
|
|
return response
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error connecting to Termbin: {e}")
|
|
|
|
return None
|
|
|
|
|
2024-07-26 17:43:15 +03:00
|
|
|
def publish_to_mozilla(content):
|
|
|
|
url = 'https://pastebin.mozilla.org/api/'
|
|
|
|
data = {
|
|
|
|
'content': content,
|
|
|
|
'expires': '86400', # 24 hours
|
|
|
|
'format': 'text',
|
|
|
|
'lexer': '_text'
|
|
|
|
}
|
|
|
|
response = requests.post(url, data=data)
|
|
|
|
if response.status_code == 200:
|
2024-07-28 11:12:44 +03:00
|
|
|
# Mozilla returns full link to the paste
|
|
|
|
return f"{response.text}"
|
2024-07-26 17:43:15 +03:00
|
|
|
return None
|
|
|
|
|
|
|
|
def publish_to_dpaste(content):
|
|
|
|
url = 'https://dpaste.org/api/'
|
|
|
|
data = {
|
|
|
|
'content': content,
|
|
|
|
'format': 'url'
|
|
|
|
}
|
|
|
|
response = requests.post(url, data=data)
|
|
|
|
if response.status_code == 200:
|
|
|
|
return response.text.strip()
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2024-07-28 11:12:44 +03:00
|
|
|
def publish_to_pastesh(content):
|
|
|
|
HOST = 'https://paste.sh'
|
|
|
|
VERSION = 'v2'
|
|
|
|
|
|
|
|
# Generate ID
|
|
|
|
id = f"p{secrets.token_urlsafe(6)}"
|
|
|
|
|
|
|
|
# Create a temporary file
|
|
|
|
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file:
|
|
|
|
temp_file_path = temp_file.name
|
|
|
|
|
|
|
|
# Write content to the temporary file
|
|
|
|
temp_file.write(content)
|
|
|
|
temp_file.flush()
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Prepare headers
|
|
|
|
headers = {
|
|
|
|
'X-Server-Key': '',
|
|
|
|
'Content-type': f'text/vnd.paste.sh-{VERSION}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Send the request
|
|
|
|
with open(temp_file_path, 'rb') as file:
|
|
|
|
response = requests.post(f"{HOST}/{id}", headers=headers, data=file)
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
return f"{HOST}/{id}"
|
|
|
|
else:
|
|
|
|
print(f"Error: Status code {response.status_code}")
|
|
|
|
print(f"Response: {response.text}")
|
|
|
|
return None
|
|
|
|
|
|
|
|
finally:
|
|
|
|
# Clean up the temporary file
|
|
|
|
os.unlink(temp_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
def publish_to_multiple_pastebins(file_path):
|
2024-07-26 17:33:17 +03:00
|
|
|
# Read the file content
|
|
|
|
with open(file_path, 'r') as file:
|
|
|
|
file_content = file.read()
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
|
2024-07-26 17:43:15 +03:00
|
|
|
# Publish to Termbin
|
|
|
|
termbin_url = publish_to_termbin(file_content)
|
|
|
|
if termbin_url:
|
|
|
|
results['Termbin'] = termbin_url
|
|
|
|
|
2024-07-26 17:33:17 +03:00
|
|
|
# Publish to Mozilla Pastebin
|
|
|
|
mozilla_url = publish_to_mozilla(file_content)
|
|
|
|
if mozilla_url:
|
|
|
|
results['Mozilla Pastebin'] = mozilla_url
|
|
|
|
|
2024-07-26 17:43:15 +03:00
|
|
|
# Publish to Dpaste
|
|
|
|
dpaste_url = publish_to_dpaste(file_content)
|
|
|
|
if dpaste_url:
|
|
|
|
results['Dpaste'] = dpaste_url
|
|
|
|
|
2024-07-28 11:12:44 +03:00
|
|
|
# Publish to CPaste
|
|
|
|
cpaste_url = publish_to_cpaste(file_path)
|
|
|
|
if cpaste_url:
|
|
|
|
results['CPaste'] = cpaste_url
|
|
|
|
|
2024-07-26 17:33:17 +03:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
# Example usage
|
|
|
|
file_path = 'test.txt'
|
|
|
|
|
|
|
|
results = publish_to_multiple_pastebins(file_path)
|
|
|
|
|
|
|
|
for service, url in results.items():
|
|
|
|
print(f"{service}: {url}")
|