{"action":"created","issue":{"url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/1","labels_url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/1/comments","events_url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/1/events","html_url":"https://github.com/SAPikachu/pdnsd/issues/1","id":108947600,"number":1,"title":"pdnsd doesn't work with ssh ProxyCommand option","user":{"login":"hillz1","id":11052416,"avatar_url":"https://avatars.githubusercontent.com/u/11052416?v=3","gravatar_id":"","url":"https://api.github.com/users/hillz1","html_url":"https://github.com/hillz1","followers_url":"https://api.github.com/users/hillz1/followers","following_url":"https://api.github.com/users/hillz1/following{/other_user}","gists_url":"https://api.github.com/users/hillz1/gists{/gist_id}","starred_url":"https://api.github.com/users/hillz1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hillz1/subscriptions","organizations_url":"https://api.github.com/users/hillz1/orgs","repos_url":"https://api.github.com/users/hillz1/repos","events_url":"https://api.github.com/users/hillz1/events{/privacy}","received_events_url":"https://api.github.com/users/hillz1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-29T19:59:55Z","updated_at":"2015-09-30T01:12:02Z","closed_at":null,"body":"Hi, I use openssh, redsocks and pdnsd on my router to create an ssh tunneling and transparent proxy, pdnsd works fine when I use the command:\r\n```\r\nssh -vND 1080 username@server\r\n```\r\nbut when I use:\r\n```\r\nssh -o \"ProxyCommand corkscrew 127.0.0.1 3339 %h %p\" -vND 1080 username@server\r\n```\r\nit refuses to connect to the internet, which option in the config file I should change / add ?\r\nHere is the current config file that I use:\r\n```\r\nglobal {\r\n    # debug = on;          \r\n    perm_cache=1024;\r\n    cache_dir=\"/var/pdnsd\";\r\n    run_as=\"root\";\r\n    server_port = 1053;    \r\n    server_ip = any;\r\n    status_ctl = on;\r\n    query_method=tcp_only; \r\n    min_ttl=15m;\r\n    max_ttl=1w;\r\n    timeout=10;\r\n    verbosity=3;\r\n}\r\n\r\nserver {\r\n    label= \"gyt\";           \r\n    ip = 8.8.8.8,8.8.4.4; \r\n    root_server = on;        \r\n    uptest = none;\r\n    exclude = 127.0.0.1;          \r\n}\r\n\r\nsource {\r\n    owner=localhost;\r\n    file=\"/etc/hosts\";\r\n}\r\n\r\nrr {\r\n    name=localhost;\r\n    reverse=on;\r\n    a=127.0.0.1;\r\n    owner=localhost;\r\n    soa=localhost,root.localhost,42,86400,900,86400,86400;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/comments/144240490","html_url":"https://github.com/SAPikachu/pdnsd/issues/1#issuecomment-144240490","issue_url":"https://api.github.com/repos/SAPikachu/pdnsd/issues/1","id":144240490,"user":{"login":"hillz1","id":11052416,"avatar_url":"https://avatars.githubusercontent.com/u/11052416?v=3","gravatar_id":"","url":"https://api.github.com/users/hillz1","html_url":"https://github.com/hillz1","followers_url":"https://api.github.com/users/hillz1/followers","following_url":"https://api.github.com/users/hillz1/following{/other_user}","gists_url":"https://api.github.com/users/hillz1/gists{/gist_id}","starred_url":"https://api.github.com/users/hillz1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hillz1/subscriptions","organizations_url":"https://api.github.com/users/hillz1/orgs","repos_url":"https://api.github.com/users/hillz1/repos","events_url":"https://api.github.com/users/hillz1/events{/privacy}","received_events_url":"https://api.github.com/users/hillz1/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T01:12:02Z","updated_at":"2015-09-30T01:12:02Z","body":"```\r\n#!/usr/bin/python\r\n\r\nimport socket,select,time,base64,os,sys,re\r\ndef chrtobyte(ch):\r\n    for a in range(0,255):\r\n          if chr(a)==ch:\r\n               return a\r\ndef encrypt(s):\r\n    so=''\r\n    for a in range(0,len(s)):\r\n        so=so+chr(chrtobyte(s[a])+1)\r\n    return so\r\n\r\ndef decrypt(s):\r\n    so=''\r\n    for a in range(0,len(s)):\r\n        so=so+chr(chrtobyte(s[a])-1)\r\n    return so\r\n\r\nif len(sys.argv) == 2:\r\n  if sys.argv[1] == \"ipe\":\r\n    fo=open('/root/config','r')\r\n    for line in fo:\r\n      if line.find('profile')==0:\r\n        profile=line.split(\"'\")[1]\r\n        profile='/root/profiles/'+profile\r\n    fo.close()\r\n    fo=open(profile)\r\n    fw=open(profile+'__','w')\r\n    for line in fo:\r\n      copy=line\r\n      if line.find('ip_rule')==0:\r\n        ip_rule=line.split(\"'\")[1]\r\n        if (len(ip_rule)>0 and not re.match(\"^ANGELBEATS\",ip_rule)):\r\n          copy=base64.urlsafe_b64encode(ip_rule)\r\n          copy=encrypt(copy)\r\n          copy=\"ip_rule '\"+\"ANGELBEATS\"+copy+\"'\\n\"\r\n          print copy\r\n      fw.write(copy)\r\n    fo.close()\r\n    fw.close()\r\n    os.remove(profile)\r\n    os.rename(profile+'__',profile)\r\n    exit()\r\n\r\n  if sys.argv[1] == \"ipd\":\r\n    fo=open('/root/config','r')\r\n    for line in fo:\r\n      if line.find('profile')==0:\r\n        profile=line.split(\"'\")[1]\r\n        profile='/root/profiles/'+profile\r\n    fo.close()\r\n    fo=open(profile)\r\n    fw=open(profile+'__','w')\r\n    for line in fo:\r\n      copy=line\r\n      if line.find('ip_rule')==0:\r\n        ip_rule=line.split(\"'\")[1]\r\n        if re.match(\"^ANGELBEATS\",ip_rule):\r\n          ip_rule = ip_rule.replace(\"ANGELBEATS\",\"\")\r\n          copy=ip_rule\r\n          copy=decrypt(copy)\r\n          copy=base64.urlsafe_b64decode(copy)\r\n          copy=\"ip_rule '\"+copy+\"'\\n\"\r\n          print copy\r\n      fw.write(copy)\r\n    fo.close()\r\n    fw.close()\r\n    os.remove(profile)\r\n    os.rename(profile+'__',profile)\r\n    exit()\r\n\r\nfo=open('/root/config','r')\r\nfor line in fo:\r\n  if line.find('#')==0:\r\n    line='' \r\n  else:\r\n    if line.find('profile')==0:\r\n      profile=line.split(\"'\")[1]\r\n      profile='/root/profiles/'+profile\r\n    if line.find('file_config')==0:\r\n      akun_vpn=line.split(\"'\")[1]\r\n      akun_vpn='/root/crt/'+akun_vpn\r\n    if line.find('ssh_account')==0:\r\n      akun_ssh=line.split(\"'\")[1]\r\n      akun_ssh='/root/gconf/'+akun_ssh\r\nfo.close()\r\nfo=open(akun_vpn)\r\nfor line in fo:\r\n  if line.find('remote')==0:\r\n    hostvpn=line.split()\r\n    if len(hostvpn) > 1:\r\n      hostvpn=hostvpn[1] + \":\" + hostvpn[2]\r\nfo.close()\r\nfo=open(akun_ssh)\r\nfor line in fo:\r\n  if line.find('Host')==0:\r\n    hostssh=line.split(\" \")[1].rstrip()\r\n  if line.find('Port')==0:\r\n    portssh=line.split(\" \")[1].rstrip()\r\n    hostssh=hostssh+\":\"+portssh\r\nfo.close()\r\nfo=open(profile)\r\nfor line in fo:\r\n  if line.find('use_vpn')==0:\r\n    use_vpn=line.split(\"'\")[1]\r\n  if line.find('use_ssh')==0:\r\n    use_ssh=line.split(\"'\")[1]\r\nfo.close()\r\nif use_vpn == 'yes':\r\n  server=hostvpn\r\nif use_ssh == 'yes':\r\n  server=hostssh\r\nfo=open(profile)\r\nfw=open(profile+'__','w')\r\nfor line in fo:\r\n  copy=line\r\n  if line.find('#')==0:\r\n    line='' \r\n  else:\r\n    if line.find('proxy_ip')<>-1:\r\n         proxy_ip=line.split(\"'\")[1]\r\n         proxy_ip=proxy_ip.replace('^server^',server,1)\r\n    if line.find('proxy_port')==0:\r\n         proxy_port=line.split(\"'\")[1]\r\n    if line.find('payload_inject')==0:\r\n         payload=line.split(\"'\")[1]\r\n         if len(payload)>10:\r\n              if payload.find('HTTP')<>-1:\r\n                  copy=base64.urlsafe_b64encode(payload)\r\n                  copy=encrypt(copy)\r\n                  copy=\"payload_inject '\"+copy+\"'\\n\"\r\n              else:\r\n                  copy=\"payload_inject '\"+payload+\"'\\n\"\r\n                  payload=decrypt(payload)\r\n                  payload=base64.urlsafe_b64decode(payload)                  \r\n              payload=payload.replace('^server^',server,3)\r\n              payload=payload.replace('#10','\\n')\r\n              payload=payload.replace('#13','\\r')\r\n  fw.write(copy)  \r\nfo.close()\r\nfw.close()\r\nos.remove(profile)\r\nos.rename(profile+'__',profile)\r\nprint 'proxy:'+proxy_ip+':'+proxy_port\r\nprint 'inject version 07/09/15 Modified by Galih'\r\nforward_to=(proxy_ip,int(proxy_port))\r\nlisten=3339\r\nbuffer_size = 2048\r\nclass Forward:\r\n    def __init__(self):\r\n        self.forward = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\r\n\r\n    def start(self, host, port):\r\n        try:\r\n            self.forward.connect((host, port))\r\n            return self.forward\r\n        except Exception, e:\r\n            print e\r\n            return False\r\n\r\nclass TheServer:\r\n    input_list = []\r\n    channel = {}\r\n    channel_ = {}\r\n    request = {}\r\n\r\n    def __init__(self, host, port):\r\n        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\r\n        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\r\n        self.server.bind((host, port))\r\n        self.server.listen(200)\r\n\r\n    def main_loop(self):\r\n        self.input_list.append(self.server)\r\n        while 1:\r\n            ss = select.select\r\n            inputready, outputready, exceptready = ss(self.input_list, [], [])\r\n            for self.s in inputready:\r\n                if self.s == self.server:\r\n                    self.on_accept()\r\n                    break\r\n                try:\r\n                    self.netdata = self.s.recv(buffer_size)\r\n                except Exception, e:\r\n                    self.netdata =''\r\n                if len(self.netdata) == 0:\r\n                    self.on_close()\r\n                else:\r\n                    if cmp(self.channel[self.s],self.channel_[self.s]):\r\n                        self.on_outbounddata()\r\n                    else:\r\n                        self.on_execute()\r\n\r\n    def on_accept(self):\r\n        forward = Forward().start(forward_to[0], forward_to[1])\r\n        clientsock, clientaddr = self.server.accept()\r\n        if forward:\r\n            self.input_list.append(clientsock)\r\n            self.input_list.append(forward)\r\n            self.channel[clientsock] = forward\r\n            self.channel[forward] = clientsock\r\n            self.channel_[clientsock] = forward\r\n            self.channel_[forward] = forward\r\n        else:\r\n            print \"Proxy \",forward_to,\" tidak merespon\",\r\n            print \"Closing connection with client side\", clientaddr\r\n            clientsock.close()\r\n\r\n    def on_close(self):\r\n        self.input_list.remove(self.s)\r\n        self.input_list.remove(self.channel[self.s])\r\n        out = self.channel[self.s]\r\n        self.channel[out].close()  \r\n        self.channel_[out].close() \r\n        self.channel[self.s].close()\r\n        self.channel_[self.s].close()\r\n        del self.channel[out]\r\n        del self.channel_[out]\r\n        del self.channel[self.s]\r\n        del self.channel_[self.s]\r\n\r\n        \r\n\r\n    def on_execute(self):\r\n        netdata = self.netdata\r\n#-----------------------------------------------------------\r\n        if netdata.find(\"CONNECT\") ==0:\r\n            req=netdata.split('HTTP')[0]\r\n            payloads=payload           \r\n            payloads=payloads.replace('^request^',req)\r\n            if payloads.find('|')<>-1:\r\n                 pay=payloads.split('|')                  \r\n                 self.request[self.channel[self.s]]=pay[1];\r\n                 netdata=pay[0]\r\n            else:\r\n                 netdata=payloads\r\n            #print netdata\r\n        try:\r\n            self.channel[self.s].send(netdata)\r\n        except Exception, e:\r\n            print e            \r\n#-----------------------------------------------------------\r\n    def on_outbounddata(self):\r\n        netdata = self.netdata\r\n        if netdata.find('HTTP/1.') ==0:\r\n            if payload.find('|')<>-1:\r\n                if self.request[self.s] != '':\r\n                    time.sleep(0.5)                \r\n                    print self.request[self.s]\r\n                    self.channel_[self.s].send(self.request[self.s])\r\n                    self.request[self.s]=''\r\n            netdata='HTTP/1.1 200 Connection established\\r\\n\\r\\n'\r\n        try:\r\n            self.channel[self.s].send(netdata)\r\n        except Exception, e:\r\n            print e\r\n            \r\n#-----------------------------------------------------------\r\n       \r\nif __name__ == '__main__':\r\n    server = TheServer('0.0.0.0', listen)\r\n    try:\r\n        server.main_loop()\r\n    except KeyboardInterrupt:\r\n        print \"Ctrl C - Stopping server\"\r\n```"}}