码迷,mamicode.com
首页 > 其他好文 > 详细

配合混淆ssh(obfuscated)的proxy智能线路选择

时间:2015-01-23 13:31:03      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

也不知道怎么了,一些网站访问总是不稳定, 速度也不能令人满意(呵呵,你懂的),总是上演道高一尺魔高一丈的激情攻防游戏。最近又学习了obfuscated ssh,作者08年开发出来但一直没受到重视,甚至连openssh都不接受作者的提交,然而谁也不知道路在何方,巧的是由于祖国的日益强大,obfuscated ssh近几年火了,还火的一塌糊涂。不多说,更多详情自己google、baidu吧,下边只讲一下安装使用过程。


项目地址:https://github.com/aligo/obfuscated-openssh


编译安装的话最好不要覆盖现有版本的ssh,使用时便于自主选择,下边的主要操作基于mac,linux下类似不多说,据说ubuntu已经默认支持了(没验证),windows就不提了装个potty就可以了。


一、以下是obfuscated ssh mac下的安装配置过程

下载源码:

https://github.com/brl/obfuscated-openssh/archive/master.zip

配置参数设置新目录:

?  brl-obfuscated-openssh-ca93a2c  ./configure  --prefix=/usr/local/newssh --sysconfdir=/etc/newssh

make:

?  brl-obfuscated-openssh-ca93a2c  make

技术分享

在mac下make好像很多人都遇到了这个问题,解决方法很简单:

先make clean

找到Makefile的57行最后加入-lresolv,然后在进行make & make install

?  brl-obfuscated-openssh-ca93a2c  cat -n Makefile|grep LDFLAGS=
    57 LDFLAGS=-L. -Lopenbsd-compat/  -fstack-protector-all -lresolv



安装后效果如下:

技术分享


使用:

/usr/local/newssh/bin/ssh -fCN  -Z obfuscate_keyword  ssh_user_name@ssh_server -p 110  -D 127.0.0.1:7070


这样就建立了完全的加密连接(初始化handshake的加密、ssh session的加密),设想如果有多个server的话,如何选择最快的server?


重点来了,那么可以结合ping、traceroute等检测手段选择最快的server进行连接(精华都在下边的脚本里,自己看),然后在结合crontab定期检测proxy的可用性,自动重连,呵呵,爽不,这里只贴出自己的脚本,详见https://github.com/LaiJingli/fastproxy


?  fastproxy  cat fastproxy_v2.sh
#!/bin/bash


###port forwarding support obfuscated ssh handshak using ssh as socks proxy server for fast access intranet web sites behind firewall from anywhere.
###by lai


###备选服务器列表
ssh_servers=(vip01.tttt.cn
vip02.tttt.cn
vip03.tttt.cn
vip04.tttt.cn
vip05.tttt.cn
vip06.tttt.cn
)
###备选端口列表
ssh_server_ports=(80 110 11231 10813)


###ssh相关参数定义
ssh_user_name=sshuser1
ssh_user_pass=123456
sshpass_cmd="/bin/sshpass -p$ssh_user_pass "
ssh_obf_cmd="/usr/local/newssh/bin/ssh -o StrictHostKeyChecking=no -p 110 -fCND 127.0.0.1:7070 -Z keyworks "


###定义运行此脚本所在os的ping返回结果格式
ping_os_type_macos="round-trip"
ping_os_type_linux="rtt"
ping_os_type=$ping_os_type_macos




#######以下内容不需要用户修改,自定义参数见上文变量定义部分
###parallel background detect which ssh server is the fastest according round-trip-time using ping and traceroute(for further support)
for i in `seq 0 $((${#ssh_servers[@]} - 1))` ;do
ip=${ssh_servers[$i]}
#echo $i $ip
###get the average round-trip-time
###ping 3次,每次间隔0.1s,超时1s
ping -c 2 -i 0.1 -t 1 $ip |grep $ping_os_type|awk -F/ ‘{print $5}‘ > /tmp/${ip}_rtt.log 2>&1 &
###记录每次ping进程的pid,以便后续根据pid是否存在判断进程是否早学完
pids[$i]=$!
#echo pid of $ip ${pids[$i]}
done




####循环检查pids数组中的pid是否运行结束的函数
pids_length=${#pids[@]}
array_check () {
   for i in `seq 0 $((${#pids[@]} - 1))` ;do
      #echo -------------------------------------array for loop----------------------
      if [  ${pids[$i]} == 0 ] ;then
         echo NULL >/dev/null
      else
      ####通过ps动态检查pid是否结束,返回0说明进程还没有结束
         ps aux|awk ‘{print $2}‘ | grep  ^${pids[$i]}$ 2>&1 >/dev/null
         pidstatus=$?
         ###if pids is not exists,that indecates the process is over,and display execute result,clean respective array elements
         if [ $pidstatus != 0 ] ;then
            ####进程结束后,打印执行结果log
   ip=${ssh_servers[$i]}
   rtt=`cat /tmp/${ip}_rtt.log`
   rtts[$i]=$rtt
   echo  "[$i] ping detect of ${ssh_servers[$i]} is over,and it‘s rtt is ${rtts[$i]} ms"
   #####同时pids数组中对应pid重置为0
            pids[$i]=0
   ####进程结束,返回200供后续判断
   return 200
   break
fi
      fi
###wait for 1 seconds to check whether the pids is over
#sleep 0.1
   done
}




####如果完成任务数complete_num不等于pids数组长度,则循环直到所有任务结束
complete_num=0
while [ ${complete_num} != ${pids_length} ] ;do
#echo =================================while loop=======================================
for ((j=0;j<${pids_length};j++)) ;do
array_check
####根据array_check函数返回值是否成功来确定complete_num数的增加
if [ $? == 200 ] ;then
complete_num=$((${complete_num}+1))
####打印最近任务完成的数量
echo -e "\033[35m\033[05m Ping Detect Report: complete_tasks/total_tasks:[${complete_num}/${pids_length}]\033[0m"
fi
done
done




###比较取到rtt最小的server地址
###初始化最小平均round-trip-time
min_rtt=10000
for i in `seq 0 $((${#ssh_servers[@]} - 1))` ;do
rtt=${rtts[$i]}
###如果当前rtt比最小的min_rtt还小,则min_rtt=$rtt
if  [[ $(echo "$rtt < $min_rtt" |bc) = 1 ]];then
min_rtt=$rtt
min_ip=${ssh_servers[$i]}
fi
done
echo ------------------------------
echo the fastest response time is $min_rtt ms of $min_ip ,to connect this server,plese wait a moment......




###kill the ssh session if it‘s pid is exist.
#ps aux|grep $ssh_user_name
ps aux|grep $ssh_user_name|grep -v grep|awk ‘{system("kill -9 "$2)}‘
#ps aux|grep $ssh_user_name|grep -v grep|awk ‘{print $2)}‘|xargs kill -9
#echo ------------------------------
###make connection to the fastest server
$sshpass_cmd$ssh_obf_cmd$ssh_user_name@$min_ip
pidstatus=$?
if [[ $pidstatus = 0 ]];then
echo Good luck,you have alredeay connect to the fastest server!
else
echo ERROR OCCUR,PLEASE CHECK.
fi
#echo ------------------------------
ps aux|grep $ssh_user_name




?  fastproxy





配合混淆ssh(obfuscated)的proxy智能线路选择

标签:

原文地址:http://blog.csdn.net/xuyaqun/article/details/42970627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!