Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Wednesday, February 28, 2018

Expect to login in ssh server through balabit

#!/usr/bin/expect -f

trap {
   set XZ [stty rows   ]
   set YZ [stty columns]
   stty rows $XZ columns $YZ < $spawn_out(slave,name)
} WINCH


proc getpass pwprompt {
       set oldmode [stty -echo -raw]
       send_user "\n     $pwprompt"
       set timeout -1
       expect_user -re "(.*)\n"
       send_user "\n"
       eval stty $oldmode
       return $expect_out(1,string)
}

set host [lrange $argv 0 0]

#Save Last Path ########
set last_path_file "/tmp/.save_bala_ssh_$host.txt"
if {[file exists $last_path_file]} {
       set f [open "/tmp/.save_bala_ssh_$host.txt"]
       set lp [split [read $f] "\n"]
       set last_path [lindex $lp 1]
       send_user "Last Path for host $host: $last_path\n"
       close $f
}
########################

#set user [lrange $argv 1 1]
set user "usuario_balabit"
set path [lrange $argv 1 1]
#set pass [getpass "Password: "]
set pass "senha_balabit"
set timeout -1
#spawn -noecho bash;
#send "ssh -A $host\r"
spawn ssh -t $host
set passwords { "senha1" "senha2" "senha3" }
set try 0
##
set timeout 2
expect {
       "Gateway username: " {
               send -- "$user\r"
               exp_continue
       }

       "Gateway password: " {
               send -- "$pass\r"
               exp_continue
       }

       "password:" {
               if { $try >= [llength $passwords] } {
                       send_error ">>> wrong passwords\n"
                               exit 1
               }
               send -- "[lindex $passwords $try]\r"
               incr try
               set timeout 3
               exp_continue
       }

       "denied" {
               set timeout 5
               exp_continue
       }

       timeout {
               #interact
               send_user "\nOK Cool! Finally Connected\n"
               if { $path != "" } {
                       if { $path != "-l" } {
                               send  -- "\nclear\ncd $path\n"
                       } else {
                               send  -- "\nclear\ncd $last_path\n"
                       }
               }
               #interact
               set CTRLZ \032
               interact {
                       -reset $CTRLZ {exec kill -STOP [pid]}
                       #\003   exit
                       #mostra_data {
                       #       send_user "The date is [exec date]."
                       #}
                       #foo {
                       #       send_user "bar"
                       #}
                       #\001   {send_user "you typed a control-A\n";
                       #       send "\001"
                       #}
                       #\002   {send_user "you typed a control-B\n";
                       #       send "\002"
                       #}
                       ç {
                               send "pwd\r"
                               expect "/*\n"
                               puts [open $last_path_file w] $expect_out(buffer)
                       }
               }
       }
}

Friday, July 1, 2016

Connect to FTP without password using .netrc file

create a file
#vi ~/.netrc

machine myftpserver
login myusername
password mypassword

Wednesday, June 8, 2016

Simple Webserver to host/share files in Python

server.py

import SimpleHTTPServer
import SocketServer

PORT = 80

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()


Use sudo to use port 80
$ sudo python server.py


or
$ sudo yum install python-pip
#pip install SimpleHTTPServer
$ sudo python -m SimpleHTTPServer 80


#firefox http://localhost/

Blog Archive