3

I want to list the networks from a airodump command and then assign a number for each network.Output of airodump is like this

CH  1 ][ Elapsed: 24 s ][ 2022-06-22 11:12 

 BSSID              PWR RXQ  Beacons    #Data, #/s  CH   MB   ENC CIPHER  AUTH WPS                ESSID

60:8D:26:XX:XX:XX  -87  29       38       36    1   1  195   WPA2 CCMP   PSK  2.0                network1  
34:57:60:XX:XX:XX  -93   0        8        0    0   6  130   WPA2 CCMP   PSK  2.0                MOVISTAR_XXX             
C8:B4:22:XX:XX:XX  -90   6       23        0    0   11  130   WPA2 CCMP   PSK Locked              MOVISTAR_XXXX             
94:6A:B0:XX:XX:XX  -89   2       34        3    0   6  130   WPA2 CCMP   PSK  2.0                MiFibra-XXXX     

i want to do something like this with a select number to choose the network

0.    60:8D:26:XX:XX:XX  -87  29       38       36    1   1  195   WPA2 CCMP   PSK  2.0                network1  
1.    34:57:60:XX:XX:XX  -93   0        8        0    0   6  130   WPA2 CCMP   PSK  2.0                MOVISTAR_XXX             
2.    C8:B4:22:XX:XX:XX  -90   6       23        0    0   11  130   WPA2 CCMP   PSK Locked              MOVISTAR_XXXX             
3.    94:6A:B0:XX:XX:XX  -89   2       34        3    0   6  130   WPA2 CCMP   PSK  2.0                MiFibra-XXXX 

Here is my script

#!/usr/bin/env ruby


require 'open3'
require 'highline/import'


def error
puts "\e[1;31m[*] ERROR: exit in 5s.\e[0m"
sleep 5
abort("BYE..")
end

WAIT_FOR_AIRODUMP = 20 #seconds

puts "\e[1;33m[*] wifi card:\e[0m"
system"airmon-ng"
puts "Choose wifi card: "
$wlan_name = gets.chomp
puts "#{$wlan_name} choosen"
if $wlan_name.chomp.start_with?('wlan', 'wlx', 'wlp')
  `echo #{$wlan_name} > scancarte.txt`
   puts "\e[1;32m[*] checking... OK.\e[0m"
else
error()
end


def get_wlan_interface
      wlan_interface = $wlan_name
  if wlan_interface[wlan_interface.length-3..-1] == 'mon'
    monitor_enabled = true
  else
    monitor_enabled = false
  end
  if wlan_interface.length > 0
    if monitor_enabled
      puts "Monitor in: #{wlan_interface}"
    else
      puts "Card: #{wlan_interface}"
    end
  else
    puts "No card detected, exit..."
    exit!
  end
  {
      name: wlan_interface,
      monitor: monitor_enabled
  }
end

def run_airmon_zc(wlan_name)
  `ip link set #{wlan_name} down`.delete! ":"
  puts "Starting monitor mode: #{wlan_name}".delete! ":"
  system("iw dev #{wlan_name} set type monitor")
  `ip link set #{wlan_name} up`.delete! ":"
end

def run_wash(wlan_name)
  puts"#{wlan_name}".delete! ":"
  cmd = "airodump-ng --encrypt wpa #{wlan_name}"
  puts "Starting airodump: #{cmd} , wait #{WAIT_FOR_AIRODUMP} seconds to see networks..."
# sleep 30
  p = IO.popen(cmd)
  process_line = false
  wifi_points = []

  Thread.new do
    p.each_line do |line|
      if process_line
        wifi_hash = process_wash_line(line)
        if wifi_hash[:enc] == "WPA2" or wifi_hash[:enc] == "WPA3"
          wifi_points << wifi_hash
        end
      end
      if line.include?('Elapsed')
        process_line = true
      end
    end
  end

  Thread.new do
    start_time = Time.now
    while true do
      sleep(5)
      diff = Time.now - start_time
      print "%.0f" % diff + '... '
      if diff > WAIT_FOR_AIRODUMP
        puts "\nExiting airodump..."
        `killall airodump-ng`
        break
      end
    end
  end.join

  wifi_points
end

def process_wash_line(line)
  fields = line.split(" ")
  wifi_point = {
      bssid: fields[0],
      channel: fields[1],
      power: fields[2],
      version: fields[3],
      enc: fields[4],
      essid: fields[5]
  }
  wifi_point
end

def select_point_to_crack(access_points, wlan_iface_name)
  access_points = access_points.sort_by { |access_point| access_point[:power] }
  puts "Choose a number (between 0 and #{access_points.length - 1}):"
  access_points.each_with_index do |access_point, idx|
    puts "#{idx}. #{access_point[:essid]} #{access_point[:bssid]} #{access_point[:power]}dB Canal: #{access_point[:channel]}"
  end
  print "Choose a correct number:"
  n = input_number(access_points.length)
  point_to_crack = access_points[n]
 `echo #{point_to_crack[:channel]} > canal.txt`
 `echo #{point_to_crack[:bssid]} > bssid.txt`
 `echo #{point_to_crack[:essid]} > ssid.txt`
  cmd = "nextscript.rb"
  puts "Name of network: #{point_to_crack[:essid]}"
  exec(cmd)
end

def input_number(max)
  while true
    input = gets
    if input.match(/^\d+$/)
      n = input.to_i
      if n < max
        break
      end
    end
    print "Chosse a number between 0 and #{max - 1}:"
  end
  n
end

# check_packages
wlan_iface = get_wlan_interface
wlan_iface_name = wlan_iface[:name]
if !wlan_iface[:monitor]
  run_airmon_zc(wlan_iface[:name])
  wlan_iface_name += ''
end
wifi_access_points = run_wash(wlan_iface_name)
select_point_to_crack(wifi_access_points, wlan_iface_name)

There is no error message when the script is launched but it just wait 20 seconeds and i can't see the networks appear with a number for each of them like expected.Code produce the followig output

Starting airodump: airocump-ng --encrypt wlan1 , wait 20 seconds to see networks..."
5... 10... 15... 20...
Exiting airodump...
Choose a number (between 0 and  )

What im missing ?

Damien
  • 31
  • 3
  • Doesn't work _how_? Your script seems to produce quite a lot of output - so what do you _really_ get before it "doesn't work" (if anything)? In general, you should learn how to debug your code to narrow down the question - it is too vague now, you should not expect that people would debug your code for you... – Konstantin Strukov Oct 27 '22 at 08:17
  • Sorry, i just edited my question with the output of the code.You say i have to learn how debug my code and im agree with that but without errors i don't know how to debug it... – Damien Oct 27 '22 at 11:07

0 Answers0