Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/extensions/extapi/service/service.rb
Views: 11795
# -*- coding: binary -*-12module Rex3module Post4module Meterpreter5module Extensions6module Extapi7module Service89###10#11# This meterpreter extension contains extended API functions for12# querying and managing Windows services.13#14###15class Service1617SERVICE_OP_START = 118SERVICE_OP_PAUSE = 219SERVICE_OP_RESUME = 320SERVICE_OP_STOP = 421SERVICE_OP_RESTART = 52223def initialize(client)24@client = client25end2627#28# Enumerate all the services on the target.29#30def enumerate31request = Packet.create_request(COMMAND_ID_EXTAPI_SERVICE_ENUM)32response = client.send_request(request)3334services = []3536response.each(TLV_TYPE_EXT_SERVICE_ENUM_GROUP) do |s|37services << {38:name => s.get_tlv_value(TLV_TYPE_EXT_SERVICE_ENUM_NAME),39:display => s.get_tlv_value(TLV_TYPE_EXT_SERVICE_ENUM_DISPLAYNAME),40:pid => s.get_tlv_value(TLV_TYPE_EXT_SERVICE_ENUM_PID),41:status => s.get_tlv_value(TLV_TYPE_EXT_SERVICE_ENUM_STATUS),42:interactive => s.get_tlv_value(TLV_TYPE_EXT_SERVICE_ENUM_INTERACTIVE)43}44end4546services.sort_by { |s| s[:name].upcase }47end4849#50# Query some detailed parameters about a particular service.51#52def query(service_name)53request = Packet.create_request(COMMAND_ID_EXTAPI_SERVICE_QUERY)54request.add_tlv(TLV_TYPE_EXT_SERVICE_ENUM_NAME, service_name)5556response = client.send_request(request)5758{59:starttype => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_STARTTYPE),60:display => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_DISPLAYNAME),61:startname => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_STARTNAME),62:path => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_PATH),63:logroup => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_LOADORDERGROUP),64:interactive => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_INTERACTIVE),65:dacl => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_DACL),66:status => response.get_tlv_value(TLV_TYPE_EXT_SERVICE_QUERY_STATUS)67}68end6970#71# Control a single service72#73def control(service_name, op)74if op.is_a? String75case op.strip.downcase76when "start"77op = SERVICE_OP_START78when "pause"79op = SERVICE_OP_PAUSE80when "resume"81op = SERVICE_OP_RESUME82when "stop"83op = SERVICE_OP_STOP84when "restart"85op = SERVICE_OP_RESTART86end87end8889unless (op.is_a? Integer) && op >= SERVICE_OP_START && op <= SERVICE_OP_RESTART90raise ArgumentError, "Invalid operation: #{op}"91end9293request = Packet.create_request(COMMAND_ID_EXTAPI_SERVICE_CONTROL)94request.add_tlv(TLV_TYPE_EXT_SERVICE_CTRL_NAME, service_name)95request.add_tlv(TLV_TYPE_EXT_SERVICE_CTRL_OP, op)96client.send_request(request)97end9899attr_accessor :client100101end102103end; end; end; end; end; end104105106