ghostunnel使用TLS加密TCP流量

很现实的问题,局域网内有态势感知和网络流量分析,这很讨厌! 那么,如何把某段流量隐藏起来,让态势感知无法分析呢? 前提条件,你需要有国外的一台 VPS 作为外援,把 TCP 流量通过 TLS 加密送到国外的服务器,然后再转发到正确的目标服务器上,这样就不会被人追踪了。 这里推荐 Ghostunnel ,这是个 Go 的程序,只有一个执行文件。配合 certik 证书生成,就完美了。 项目地址:https://github.com/ghostunnel/ghostunnel 首先我们使用 certik 生成三个证书,ca.pem server.pem 和 client1.pem 然后ghostunnel以及三个证书文件都放在/usr/local/bin下 一、在VPS上运行ghostunnel模式server /usr/local/bin/ghostunnel server --listen 0.0.0.0:9999 --target tr.dero.herominers.com:1117 --keystore server.pem --cacert ca.pem --allow-cn client1 --unsafe-target 上面监听了端口0.0.0.0:9999(监听0.0.0.0必须加参数–unsafe-target),远程转发到dero的矿池端口1117,只允许验证过的cn client1连接。 二、在本地机器上运行ghostunnel模式client /usr/local/bin/ghostunnel client --listen localhost:9999 --target 193.42.114.129:9999 --keystore client.pem --cacert ca.pem 本地监听localhost:9999,所以不用加–unsafe-target参数,然后连接到远程 vps 服务器,ip地址是193.42.114.129,端口是9999 这样就完成了。可以放心的启动程序,连接到本地端口localhost:9999,TCP流量就会被隐藏起来,不会被分析到.

2021年10月19日

Certik 证书签发软件

我们会有很多时候需要用到TLS证书,一个非常方便、小众的工具就是 certik 。 这个软件纯由 Go 组成,就一个可执行文件,使用了 etcd 的 boltdb 格式存放所有的证书。 软件地址:https://github.com/opencoff/certik 使用: 一、初始化证书库 ./certik -v tls.db init CA 二、签发一张server证书 #./certik -v tls.db server -i IP.ADDR.ES server.domain.name ./certik -v tls.db server -i 193.42.114.129 server 上面我们 server 的 ip 是193.42.114.129,域名简洁起见就叫 server 了 。 三、签发一张client1证书 ./certik -v tls.db client client1 四、查看证书库 ./certik -v tls.db list 我们就可以看到三个证书了,一个 CA ,一个 server ,一个 client1 五、导出各个证书 #导出CA ./certik -v tls.db export --root-ca #导出server ./certik -v tls.db export server #导出client1 ./certik -v tls.db export client1 以上就可以得到各个东西了。 ...

2021年10月19日

使用IPSET封掉某个国家整个的访问

现在国内都禁止挖币,什么币安、火币、cnspark之类的都不允许国内 IP 访问了。 如何实现的呢? 首先需要得到国家IP段,下载地址:http://www.ipdeny.com/ipblocks/。这里以我们国家 cn 为例 步骤如下: 一、安装ipset #Debian/Ubuntu系统 apt-get -y install ipset #CentOS系统 yum -y install ipset 二、清空iptable规则 #防止设置不生效,清空之前的防火墙规则 iptables -P INPUT ACCEPT iptables -F 三、创建ipset规则集 #创建一个名为cnip的规则 ipset -N cnip hash:net #下载国家IP段,这里以中国为例 wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone #将IP段添加到cnip规则集中 for i in $(cat /root/cn.zone ); do ipset -A cnip $i; done 四、创建iptable黑名单 #扔黑名单 iptables -A INPUT -p tcp --dport 80 -m set --match-set cnip src -j DROP iptables -A INPUT -p tcp --dport 443 -m set --match-set cnip src -j DROP #然后放行其他的 iptables -P INPUT ACCEPT

2021年10月18日

OpenVPN 限制流量带宽

公司安装了 openvpn ,带来方便,但是也有很多不便的地方,机房的总带宽就那么多。 很多人共用 vpn 的时候,就会抢占带宽。 那么,我们需要限制一下,限制 openvpn 所能使用的带宽,避免抢占 WEB 的带宽 做法如下: 由于我们不是要单独限制某一个 openvpn 用户,而是限制整体,所以简单用 TC 就可以了 #!/bin/sh tc qdisc del dev tun0 root tc qdisc add dev tun0 root handle 1: htb default 1 tc class add dev tun0 parent 1: classid 1:1 htb rate 30Mbit ceil 30Mbit 解释一下: 我们 openvpn 启的是 tun0 ,所以限制的对象就是 dev tun0 首先第一行清除 tun0 的根队列 然后第二行建立 tun0 的 root 根队列为 1:0 htb ,缺省是1:1的子队列 最后一行,第三行建立 1:1 的子队列,带宽限制是 30Mbit ,注意这里是大B,就是网络术语中的带宽,换算成小b的话,需要除以8 效果很明显,直接被限制住(41兆而不是30M是因为这台机器是虚机,实体机上还有别的流量): ...

2021年10月18日

本站博客的由来以及搭建使用教程

本站这个博客的由来: 源自于 wiredcraft 的面试,这个公司让老八很是向往,可以远程工作,第一次面试是 devops ,老外见面聊了后,由代理中国人面。因为面的是K8S的东西,正好刚给画包包公司做了整体迁往阿里ACK的工程,以为没问题,实际是直接问倒了我。就好比master node上面都跑了什么进程,唉,一言难尽啊,又问到ansible的变量,回答估计也不满意,结果就挂了 知耻而后勇,后面去恶补了一下ansible和k8s的东西,实际也是实际操作居多,然后第二次面的是 sysadmin,全程老外面。还出了几道题,应该是没问题。但是工资要高了,也被刷了。 这个博客就是其中一道题,那既然搭建出来了,干脆就好好用吧。 本身自己对静态的 Blog 系统也比较感兴趣,自己主站 www.rendoumi.com 的 Blog 是由 journey 搭建的,是一个精巧的 go 程序,最妙的是它兼容 Ghost 博客系统,也能使用 Ghost 的 theme ,这样就完美的把自己以前 Ghost 的博客迁移了过去,但是,里面文章有很多过时了,但也不想清理,干脆借着这个机会,从新开始。搭一个自己喜欢的系统继续写新博客 流行的 Markdown 写作平台有Hexo和Hugo,选Hugo是因为实在是不喜欢node,弄一堆npm,迁移麻烦死。 这个博客程序基于Hugo,托管在 github,众所周知,github 是托管静态文件的地方,Markdown的最大毛病是图片。图片放在图床也不是好办法,所以图片和静态文件要在一起,下面就说一下搭建过程,我的主机是Ubuntu: 一、下载Hugo 下载地址: https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_0.88.1_Linux-64bit.tar.gz wget https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_0.88.1_Linux-64bit.tar.gz tar zxvf hugo_0.88.1_Linux-64bit.tar.gz 二、初始一个博客写作目录 ./hugo new site MyBlog ​ 三、下载theme cd MyBlog git clone https://github.com/halogenica/beautifulhugo.git themes/beautifulhugo echo theme = \"beautifulhugo\" >> config.toml ​ 四、写一篇新文章 cd MyBlog ../hugo new posts/my-first-post.md echo "#### This is another Blog" >> content/posts/my-first-post.md 五、运行server,build草稿 cd MyBlog ../hugo server --buildDrafts ​ ...

2021年10月15日

Iphone手机的https抓包

上一篇文章,我们实施了Ubuntu下wifi热点的搭建,那么,其实我是想抓我iphone手机的https明文流量包来着。 怎么抓取呢? 方法也很简单 一、安装 mitmproxy 有wifi热点那台机器的wlan网卡地址是192.168.222.1,就在那台上安装,便于抓取 pip install mitmproxy 二、运行mitmproxy mitmproxy -p 8080 三、配置iphone安装mitm证书 打开手机,获取wifi热点,设置这个wifi使用手机代理,192.168.222.1:8080 然后用Safari浏览器打开网址:http://mitm.it 找到IOS那行,仔细看一看说明 点击 Get mitmproxy-ca-cert.pem 安装描述文件 安装完以后,在设置 –> 已下载描述文件,安装描述文件 安装好以后会显示绿色的已验证 然后在手机上用 safari 访问网址:https://ip138.com 回到 Ubuntu 的命令行窗口,上下选中抓到的包,然后按回车查看,左右光标键移动,可以看到response是明文的,q键是返回上一级 四、包的拦截修改 上面演示的是常规的查看操作,下面介绍一下 mitmproxy 的另一强大功能,拦截修改 request 和 response。 输入 i,然后输入 ~s 再按回车键,这时候就进入了 response 拦截模式。如果输入 ~q 则进入 request 的拦截模式,更多的命令可以输入 ? 查看。拦截模式下的页面显示如下图所示: 其中红色的表示请求正被拦截,这时 Enter 进入后 再按 e 就可以修改 request 或者 response。修改时是用 vim 进行编辑的,修改完成后按 a 将请求放行,如果要放行所有请求输入 A 即可。 ...

2021年10月14日

Ubuntu下自建一个wifi热点供手机使用

公司的wifi信号很弱,也不保险。省事起见,还是自己建立一个好 usb无线网卡设备必须是一个 nl80211 兼容的无线设备,所以驱动就是这个:nl80211 我的操作系统是Ubuntu,如果是CentOS命令基本一样 插上wifi usb卡后 ip a 看一下网卡的名称,我这里是:wlx00a1b0817651,够长 一、安装hostapd软件 sudo apt install -y hostapd 二、建立hostapd.conf文件 vi /etc/hostapd/hostapd.conf driver=nl80211 ssid=Fast_8188 channel=10 interface=wlx00a1b0817651 wpa=2 wpa_passphrase=GreatWall2021! wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP 三、建立启动脚本/usr/local/bin/initAP.sh cat /usr/local/bin/initAP.sh #!/bin/bash start() { rfkill unblock all ifconfig wlx00a1b0817651 up 192.168.222.1 netmask 255.255.255.0 sleep 2 dnsmasq -i wlx00a1b0817651 --dhcp-range=192.168.222.10,192.168.222.20,2h #Enable NAT sysctl -w net.ipv4.ip_forward=1 iptables -F iptables -X iptables -t nat -A POSTROUTING -s 192.168.222.0/24 -j SNAT --to 192.168.41.15 hostapd -B /etc/hostapd/hostapd.conf } stop() { iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X systemctl stop dnsmasq pkill hostapd /sbin/ip link set down dev wlx00a1b0817651 } case $1 in start) start ;; stop) stop ;; *) echo "Usage: $0 {start|stop}" exit 2 esac 四、用root身份执行即可 sudo chmod 755 /usr/local/bin/initAP.sh sudo /usr/local/bin/initAP.sh start 这样就可以用自己的手机连上这个wifi热点,尽情冲浪啦。 ...

2021年10月14日

CentOS 7 Live-CD 的制作

某些场合,很有可能需要启动ISO或者USB盘,自带Linux系统,然后拯救当前损坏的系统 或者直接启动一个LIVE CentOS系统,去做某些事,比如用MegaRaid划分Raid、测试系统等等 这时候就需要制作出来一个LIVE CD的系统了 制作步骤如下: 一、安装live-tools yum -y install livecd-tools 二、准备Kickstart文件centos7-live-docker.ks 下载地址:centos7-live-docker.ks lang en_GB.UTF-8 keyboard us timezone Asia/Shanghai --isUtc #selinux --enforcing selinux --disabled #firewall --enabled --service=cockpit firewall --disabled #xconfig --startxonboot part / --size 8192 --fstype ext4 services --enabled=NetworkManager,sshd --disabled=network # Root password auth --useshadow --enablemd5 rootpw --plaintext Kalaisadog2021 repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/ repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64/ repo --name=extras --baseurl=http://mirror.centos.org/centos/7/extras/x86_64/ repo --name=epel --baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/ %packages @core kernel dracut bash firewalld NetworkManager e2fsprogs rootfiles docker openssh-server #By zhang ranrui unzip net-tools binutils wget bash-completion bc dmidecode dmraid dmraid-events lvm2 lvm2-libs kpartx mdadm parted xfsdump xfsprogs gdisk bzip2 extundelete libHX libHX-devel autoconf gcc gcc-c++ make screen telnet %end %post systemctl enable docker # By Zhang Ranrui, Add your custom script #wget http://www.rendoumi.com/soft/other/xfs_irecover -O /usr/local/bin/xfs_irecover #chmod 755 /usr/local/bin/xfs_irecover echo "Banner /etc/issue" >> /etc/ssh/sshd_config sed -i "s/After=network\.target/After=network-online\.target\nWants=network-online\.target/g" /usr/lib/systemd/system/rc-local.service chmod 755 /etc/systemd/system/rc.local.service.d chmod 644 /etc/systemd/system/rc.local.service.d/local.conf chmod 755 /etc/rc.d/rc.local systemctl enable rc-local systemctl start rc-local # FIXME: it'd be better to get this installed from a package cat > /etc/rc.d/init.d/livesys << EOF #!/bin/bash # # live: Init script for live image # # chkconfig: 345 00 99 # description: Init script for live image. ### BEGIN INIT INFO # X-Start-Before: display-manager ### END INIT INFO . /etc/init.d/functions if ! strstr "\`cat /proc/cmdline\`" rd.live.image || [ "\$1" != "start" ]; then exit 0 fi if [ -e /.liveimg-configured ] ; then configdone=1 fi exists() { which \$1 >/dev/null 2>&1 || return \$* } # Make sure we don't mangle the hardware clock on shutdown ln -sf /dev/null /etc/systemd/system/hwclock-save.service livedir="LiveOS" for arg in \`cat /proc/cmdline\` ; do if [ "\${arg##rd.live.dir=}" != "\${arg}" ]; then livedir=\${arg##rd.live.dir=} return fi if [ "\${arg##live_dir=}" != "\${arg}" ]; then livedir=\${arg##live_dir=} return fi done # enable swaps unless requested otherwise swaps=\`blkid -t TYPE=swap -o device\` if ! strstr "\`cat /proc/cmdline\`" noswap && [ -n "\$swaps" ] ; then for s in \$swaps ; do action "Enabling swap partition \$s" swapon \$s done fi if ! strstr "\`cat /proc/cmdline\`" noswap && [ -f /run/initramfs/live/\${livedir}/swap.img ] ; then action "Enabling swap file" swapon /run/initramfs/live/\${livedir}/swap.img fi mountDockerDisk() { # support label/uuid if [ "\${dockerdev##LABEL=}" != "\${dockerdev}" -o "\${dockerdev##UUID=}" != "\${dockerdev}" ]; then dockerdev=\`/sbin/blkid -o device -t "\$dockerdev"\` fi # if we're given a file rather than a blockdev, loopback it if [ "\${dockerdev##mtd}" != "\${dockerdev}" ]; then # mtd devs don't have a block device but get magic-mounted with -t jffs2 mountopts="-t jffs2" elif [ ! -b "\$dockerdev" ]; then loopdev=\`losetup -f\` if [ "\${dockerdev##/run/initramfs/live}" != "\${dockerdev}" ]; then action "Remounting live store r/w" mount -o remount,rw /run/initramfs/live fi losetup \$loopdev \$dockerdev dockerdev=\$loopdev fi # if it's encrypted, we need to unlock it if [ "\$(/sbin/blkid -s TYPE -o value \$dockerdev 2>/dev/null)" = "crypto_LUKS" ]; then echo echo "Setting up encrypted Docker device" plymouth ask-for-password --command="cryptsetup luksOpen \$dockerdev EncDocker" dockerdev=/dev/mapper/EncDocker fi # and finally do the mount mount \$mountopts \$dockerdev /var/lib/docker # if we have /home under what's passed for persistent home, then # we should make that the real /home. useful for mtd device on olpc if [ -d /var/lib/docker/docker ]; then mount --bind /var/lib/docker/docker /var/lib/docker ; fi [ -x /sbin/restorecon ] && /sbin/restorecon /var/lib/docker } findDockerDisk() { for arg in \`cat /proc/cmdline\` ; do if [ "\${arg##dockerdisk=}" != "\${arg}" ]; then dockerdev=\${arg##dockerdisk=} return fi done } if strstr "\`cat /proc/cmdline\`" dockerdisk= ; then findDockerDisk elif [ -e /run/initramfs/live/\${livedir}/docker.img ]; then dockerdev=/run/initramfs/live/\${livedir}/docker.img fi # if we have a persistent /home, then we want to go ahead and mount it if ! strstr "\`cat /proc/cmdline\`" nodockerdisk && [ -n "\$dockerdev" ] ; then action "Mounting persistent /var/lib/docker" mountDockerDisk fi # make it so that we don't do writing to the overlay for things which # are just tmpdirs/caches mount -t tmpfs -o mode=0755 varcacheyum /var/cache/yum mount -t tmpfs vartmp /var/tmp [ -x /sbin/restorecon ] && /sbin/restorecon /var/cache/yum /var/tmp >/dev/null 2>&1 if [ -n "\$configdone" ]; then exit 0 fi # add fedora user with no passwd action "Adding live user" useradd \$USERADDARGS -c "Live System User" liveuser passwd -d liveuser > /dev/null usermod -aG wheel,docker liveuser > /dev/null # Remove root password lock passwd -d root > /dev/null (echo Kalaisadog2021; echo Kalaisadog2021)|passwd root --stdin # turn off firstboot for livecd boots systemctl --no-reload disable firstboot-text.service 2> /dev/null || : systemctl --no-reload disable firstboot-graphical.service 2> /dev/null || : systemctl stop firstboot-text.service 2> /dev/null || : systemctl stop firstboot-graphical.service 2> /dev/null || : # don't use prelink on a running live image sed -i 's/PRELINKING=yes/PRELINKING=no/' /etc/sysconfig/prelink &>/dev/null || : # turn off mdmonitor by default systemctl --no-reload disable mdmonitor.service 2> /dev/null || : systemctl --no-reload disable mdmonitor-takeover.service 2> /dev/null || : systemctl stop mdmonitor.service 2> /dev/null || : systemctl stop mdmonitor-takeover.service 2> /dev/null || : # don't enable the gnome-settings-daemon packagekit plugin gsettings set org.gnome.settings-daemon.plugins.updates active 'false' || : # don't start cron/at as they tend to spawn things which are # disk intensive that are painful on a live image systemctl --no-reload disable crond.service 2> /dev/null || : systemctl --no-reload disable atd.service 2> /dev/null || : systemctl stop crond.service 2> /dev/null || : systemctl stop atd.service 2> /dev/null || : # Mark things as configured touch /.liveimg-configured # add static hostname to work around xauth bug # https://bugzilla.redhat.com/show_bug.cgi?id=679486 echo "localhost" > /etc/hostname # Fixing the lang install issue when other lang than English is selected . See http://bugs.centos.org/view.php?id=7217 /usr/bin/cp /usr/lib/python2.7/site-packages/blivet/size.py /usr/lib/python2.7/site-packages/blivet/size.py.orig /usr/bin/sed -i "s#return self.humanReadable()#return self.humanReadable().encode('utf-8')#g" /usr/lib/python2.7/site-packages/blivet/size.py EOF # bah, hal starts way too late cat > /etc/rc.d/init.d/livesys-late << EOF #!/bin/bash # # live: Late init script for live image # # chkconfig: 345 99 01 # description: Late init script for live image. . /etc/init.d/functions if ! strstr "\`cat /proc/cmdline\`" rd.live.image || [ "\$1" != "start" ] || [ -e /.liveimg-late-configured ] ; then exit 0 fi exists() { which \$1 >/dev/null 2>&1 || return \$* } touch /.liveimg-late-configured # read some variables out of /proc/cmdline for o in \`cat /proc/cmdline\` ; do case \$o in ks=*) ks="--kickstart=\${o#ks=}" ;; xdriver=*) xdriver="\${o#xdriver=}" ;; esac done # if liveinst or textinst is given, start anaconda if strstr "\`cat /proc/cmdline\`" liveinst ; then plymouth --quit /usr/sbin/liveinst \$ks fi if strstr "\`cat /proc/cmdline\`" textinst ; then plymouth --quit /usr/sbin/liveinst --text \$ks fi # configure X, allowing user to override xdriver if [ -n "\$xdriver" ]; then cat > /etc/X11/xorg.conf.d/00-xdriver.conf <<FOE Section "Device" Identifier "Videocard0" Driver "\$xdriver" EndSection FOE fi EOF chmod 755 /etc/rc.d/init.d/livesys /sbin/restorecon /etc/rc.d/init.d/livesys /sbin/chkconfig --add livesys chmod 755 /etc/rc.d/init.d/livesys-late /sbin/restorecon /etc/rc.d/init.d/livesys-late /sbin/chkconfig --add livesys-late # enable tmpfs for /tmp systemctl enable tmp.mount # enable docker systemctl enable docker.service # work around for poor key import UI in PackageKit rm -f /var/lib/rpm/__db* releasever=$(rpm -q --qf '%{version}\n' --whatprovides system-release) basearch=$(uname -i) rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch echo "Packages within this LiveCD" rpm -qa # Note that running rpm recreates the rpm db files which aren't needed or wanted rm -f /var/lib/rpm/__db* # go ahead and pre-make the man -k cache (#455968) /usr/bin/mandb # save a little bit of space at least... rm -f /boot/initramfs* # make sure there aren't core files lying around rm -f /core* # convince readahead not to collect # FIXME: for systemd cat >> /etc/rc.d/init.d/livesys << EOF # disable updates plugin cat >> /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.updates.gschema.override << FOE [org.gnome.settings-daemon.plugins.updates] active=false FOE # Show the system-config-keyboard tool on the desktop mkdir /home/liveuser/Desktop -p >/dev/null cat /usr/share/applications/system-config-keyboard.desktop | sed '/NotShowIn/d' |sed 's/Terminal=false/Terminal=true/' > /home/liveuser/Desktop/system-config-keyboard.desktop cat /usr/share/applications/liveinst.desktop | sed '/NoDisplay/d' > /home/liveuser/Desktop/liveinst.desktop chmod +x /home/liveuser/Desktop/*.desktop chown -R liveuser:liveuser /home/liveuser # Liveuser face if [ -e /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png ] ; then cp /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png /home/liveuser/.face chown liveuser:liveuser /home/liveuser/.face fi # make the installer show up if [ -f /usr/share/applications/liveinst.desktop ]; then # Show harddisk install in shell dash sed -i -e 's/NoDisplay=true/NoDisplay=false/' /usr/share/applications/liveinst.desktop # need to move it to anaconda.desktop to make shell happy #cp /usr/share/applications/liveinst.desktop /usr/share/applications/anaconda.desktop fi cat >> /usr/share/glib-2.0/schemas/org.gnome.shell.gschema.override << FOE [org.gnome.shell] favorite-apps=['liveinst.desktop','firefox.desktop', 'evolution.desktop', 'empathy.desktop', 'rhythmbox.desktop', 'shotwell.desktop', 'libreoffice-writer.desktop', 'nautilus.desktop', 'gnome-documents.desktop', 'anaconda.desktop'] FOE # set up auto-login cat > /etc/gdm/custom.conf << FOE [daemon] AutomaticLoginEnable=True AutomaticLogin=liveuser FOE # Turn off PackageKit-command-not-found while uninstalled if [ -f /etc/PackageKit/CommandNotFound.conf ]; then sed -i -e 's/^SoftwareSourceSearch=true/SoftwareSourceSearch=false/' /etc/PackageKit/CommandNotFound.conf fi # make sure to set the right permissions and selinux contexts chown -R liveuser:liveuser /home/liveuser/ restorecon -R /home/liveuser/ # Fixing default locale to us localectl set-keymap us localectl set-x11-keymap us EOF # rebuild schema cache with any overrides we installed glib-compile-schemas /usr/share/glib-2.0/schemas %end 注意,上面注释了两个地方,都可以添加软件或者运行脚本 ...

2021年10月10日

Search

search