Overview of sharp_printers.inc

Automatic Includes

These files are automatically included by the library.

Public Variable Summary

Public variables are intended to be accessed by the code that imports this library.

Name Summary
cookie
cookie
cookie
last_pass
last_user

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
build_sharp_cpe
check_sharp_default_login
error_exit
set_cookie
sharp_default_logins
sharp_login_details
update_cookie

Public Variable Details

top
top
top

last_pass

top

last_user

top

Public Function Details

build_sharp_cpe

Named Parameters

model

Code

function build_sharp_cpe(model) {


  model = tolower(model);

  if(model == "") return 'cpe:/h:sharp';

  return 'cpe:/h:sharp:' + model;

}

function set_cookie(url) {

		
top

check_sharp_default_login

Named Parameters

model

Code

function check_sharp_default_login(model) {
 
  local_var userame, password, sharp;
  global_var last_user, last_pass;

  sharp = sharp_login_details(model:model);
  if(!sharp) return FALSE;

  logins = sharp_default_logins();

  foreach login (logins) {

    user_pass = split(login,sep:":", keep:FALSE);
    username = user_pass[0];
    password = user_pass[1];

    login_data = sharp['login_data'];
    if(login_data) {
      login_data = str_replace(string:login_data, find:"%%%USERNAME%%%", replace:username);
      login_data = str_replace(string:login_data, find:"%%%PASSWORD%%%", replace:password);
    }

    len = strlen(login_data);

    if(sharp['req_type'] == "POST") {

      if(sharp['login_url_success']) {
        req = string(sharp['req_type_success'], " ", sharp['login_url_success'], " HTTP/1.1\r\n",
                     "Host: ", get_host_name(),"\r\n",
                     "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Firefox/17.0\r\n\r\n");
 
        buf = http_send_recv(port:port, data:req, bodyonly:FALSE);
        error_exit(buf:buf);

        if(eregmatch(pattern:sharp['login_success'], string:buf)) {
          return 2; # setup without auth
        }
 
      }

      req = string("POST " , sharp['login_url'], " HTTP/1.1\r\n",
                   "Host: ", get_host_name(),"\r\n",
                   "DNT: 1\r\n",
                   "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Firefox/17.0\r\n",
                   "Content-Type: application/x-www-form-urlencoded\r\n",
                   "Content-Length: ",len,"\r\n");

      if(cookie) req +=  string("Cookie: ",cookie,"\r\n");

      req += string("\r\n",login_data,"\r\n");

    } 

    else if(sharp['req_type'] == "GET") {

      if(sharp['req_auth'] == "BASIC") {

        userpass = username + ':' + password;
        userpass64 = base64(str:userpass);

        req = string("GET ", sharp['login_url']," HTTP/1.1\r\n",
                     "Host: ", get_host_name(),"\r\n");

        c_buf = http_send_recv(port:port, data:req + '\r\n', bodyonly:FALSE);
        error_exit(buf:c_buf);

        if(c_buf !~ "HTTP/1.. 401" && "HTTP/1.1 302" >!< c_buf) return 2; # setup without auth

        req += string("Authorization: Basic ",userpass64,"\r\n\r\n");

      }

    } else {
      return FALSE;
    }
 
    buf = http_send_recv(port:port, data:req, bodyonly:FALSE); # login

    if(ereg(pattern:sharp['http_status'], string:buf)) {

      update_cookie(buf:buf);

      if(sharp['login_url_success']) {

        req = string(sharp['req_type_success'], " ", sharp['login_url_success'], " HTTP/1.1\r\n",
                    "Host: ", get_host_name(),"\r\n");

        if(cookie) req +=  string("Cookie: ",cookie,"\r\n");

        req += string("User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 OpenVAS\r\n\r\n");

        buf = http_send_recv(port:port, data:req, bodyonly:FALSE);
        error_exit(buf:buf);

      }

      if(eregmatch(pattern:sharp['login_success'], string:buf)) { 
        last_user = username;
        last_pass = password;
        return 1;
      }

    }  
  }

  return FALSE;  

}  

function sharp_login_details(model) {

		
top

error_exit

Named Parameters

buf

Code

function error_exit(buf) {

  if(!buf || ereg(pattern:"HTTP/1.(0|1) (404|500)", string: buf))exit(0);

  return TRUE;

}


		
top

Named Parameters

url

Code

function set_cookie(url) {

  global_var cookie;

  req = http_get(item:url, port:port);
  buf = http_send_recv(port:port, data:req, bodyonly:FALSE);

  if("Set-Cookie:" >!< buf) return FALSE;

  co = eregmatch(pattern:"Set-Cookie: ([^; ]+)", string:buf);
  if(!isnull(co[1])) {
    cookie = co[1];
    return TRUE;
  }  

  return FALSE;

}  

function update_cookie(buf) {

		
top

sharp_default_logins

Named Parameters

Code

function sharp_default_logins() {

  return make_list("admin:Sharp","admin:1234","Administrator:admin","administrator:admin","admin:admin","admin:00000");
}  

function check_sharp_default_login(model) {

		
top

sharp_login_details

Named Parameters

model

Code

function sharp_login_details(model) {

  global_var cookie;

  sharp = make_array();

  if(model == "MX-4100N"  ||
     model == "MX-M453U"  ||
     model == "MX-5001N"  ||
     model == "MX-2700FG" ||
     model == "MX-2310U"  ||
     model == "MX-2301N"  ||
     model == "MX-M453N"  ||
     model == "MX-6200N"  ||
     model == "MX-4111N"  ||
     model == "MX-M452N"  ||
     model == "MX-M362N"  ||
     model == "MX-2614N"  ||
     model == "MX-M453U"  ||
     model == "MX-M453N"  ||
     model == "MX-M453"   ||
     model == "MX-7001N"  ||
     model == "MX-2010U"  ||
     model == "MX-M363N"  ||
     model == "MX-M363U"  ||
     model == "MX-M363"   ||
     model == "MX-M363N"  ||
     model == "MX-3110N"  ||
     model == "MX-2600N"  ||
     model == "MX-4501N"  ||
     model == "MX-6240N"  ||
     model == "MX-M283N"  ||
     model == "MX-M354N"  ||
     model == "MX-C311"   ||
     model == "MX-M502N"  ||
     model == "MX-2300N"  ||
     model == "MX-M503N"  ||
     model == "MX-B402SC") {

    if(!cookie) set_cookie(url:'/main.html');

    sharp['req_type'] = "POST";
    sharp['login_url'] = '/login.html?/main.html';
    sharp['login_data'] = 'ggt_select%2810009%29=3&ggt_textbox%2810003%29=%%%PASSWORD%%%&action=loginbtn&ggt_hidden%2810008%29=4';

    sharp['req_type_success'] = "GET";
    sharp['login_url_success'] = '/main.html'; 

    sharp['http_status'] = 'HTTP/1.. 302';
    sharp['login_success'] = '<!--Logoff \\(L\\)-->'; 

    return sharp;

  } 

  else if(model == "MX-B201D" ||
          model == "AL-2051"  ||
          model == "AL-2061"  ||
          model == "AR-M160"  ||
          model == "AR-M236"  ||
          model == "MX-M450U" ||
          model == "AR-M237"  ||
          model == "MX-M620N" ||
          model == "MX-M350N" ||
          model == "MX-M550U" ||
          model == "MX-M310N" ||
          model == "MX-M700N" ||
          model == "AR-168D"  ||
          model == "AR-M700U" ||
          model == "MX-M550N" ||
          model == "AR-M451U" ||
          model == "AR-M351U" ||
          model == "AR-M550U" ||
          model == "AR-M450U" ||
          model == "AR-M155"  ||
          model == "MX-M260N" ||
          model == "AR-M350"  ||
          model == "im3511"   ||
          model == "im4512"   ||
          model == "AR-M276") {

    sharp['req_type'] = "GET";
    sharp['login_url'] = '/password.html';
    sharp['req_auth'] = "BASIC";

    sharp['http_status'] = 'HTTP/1.. 200';
    sharp['login_success'] = '<title>Password Setup Page';

    return sharp;

  }

  exit(0); # we don't know this printer

}

function build_sharp_cpe(model) {

		
top

Named Parameters

buf

Code

function update_cookie(buf) {

  global_var cookie;

  if("Set-Cookie:" >!< buf) return FALSE;

  co = eregmatch(pattern:"Set-Cookie: ([^; ]+)", string:buf);
  if(!isnull(co[1])) {
    cookie = co[1];
    return TRUE;
  }

  return FALSE;

}

function error_exit(buf) {

		
top