Skip to content

Notes returned as valid json instead of inspected string over RPC#21292

Open
sjanusz-r7 wants to merge 1 commit intorapid7:masterfrom
sjanusz-r7:db-notes-rpc-return-notes-json-data
Open

Notes returned as valid json instead of inspected string over RPC#21292
sjanusz-r7 wants to merge 1 commit intorapid7:masterfrom
sjanusz-r7:db-notes-rpc-return-notes-json-data

Conversation

@sjanusz-r7
Copy link
Copy Markdown
Contributor

@sjanusz-r7 sjanusz-r7 commented Apr 14, 2026

Closes #21249
Tested in Pro under workspaces/1/notes

Before

Data is inspected, returned as a single string

>> rpc.call("db.notes", {})
=> 
{"notes"=>
  [{"time"=>1774630729, "host"=>"", "service"=>"", "type"=>"shellcode.bin.localpath", "data"=>"{:full_path=>\"/Users/x/.msf4/local/bin.bin\"}"},
   {"time"=>1774624210, "host"=>"", "service"=>"", "type"=>"evasion.fileformat.process_herpaderping.localpath", "data"=>"{:full_path=>\"/Users/x/.msf4/local/ioxj.exe\"}"},
   {"time"=>1776072168, "host"=>"", "service"=>"", "type"=>"evasion.fileformat.syscall_inject.localpath", "data"=>"{:full_path=>\"/Users/x/.msf4/local/met.exe\"}"},
   {"time"=>1776160364, "host"=>"127.0.0.1", "service"=>"", "type"=>"host.os.session_fingerprint", "data"=>"{:name=>\"caea2eea7ecb\", :os=>\"Debian 9.6 (Linux 6.12.76-linuxkit)\", :arch=>\"x64\"}"},
   {"time"=>1776160491, "host"=>"127.0.0.1", "service"=>"", "type"=>"host.comments", "data"=>"{:host_data=>\"hello world, this is a comment\"}"}]}

In Pro, the data is also rendered correctly:
image

After

Data is parsed correctly as a hash

>> rpc.call("db.notes", {})
=> 
{"notes"=>
  [{"time"=>1774630729, "host"=>"", "service"=>"", "type"=>"shellcode.bin.localpath", "data"=>{"full_path"=>"/Users/x/.msf4/local/bin.bin"}},
   {"time"=>1774624210, "host"=>"", "service"=>"", "type"=>"evasion.fileformat.process_herpaderping.localpath", "data"=>{"full_path"=>"/Users/x/.msf4/local/ioxj.exe"}},
   {"time"=>1776072168, "host"=>"", "service"=>"", "type"=>"evasion.fileformat.syscall_inject.localpath", "data"=>{"full_path"=>"/Users/x/.msf4/local/met.exe"}},
   {"time"=>1776160364, "host"=>"127.0.0.1", "service"=>"", "type"=>"host.os.session_fingerprint", "data"=>{"name"=>"caea2eea7ecb", "os"=>"Debian 9.6 (Linux 6.12.76-linuxkit)", "arch"=>"x64"}},
   {"time"=>1776160491, "host"=>"127.0.0.1", "service"=>"", "type"=>"host.comments", "data"=>{"host_data"=>"hello world, this is a comment"}}]}

Pro also renders the hash correctly, with no changes to functionality:
image

In Pro, the code should handle this automatically where necessary as it calls off to:

def note_data_html
      if data.kind_of?(Hash)

which handles the Hash scenario.

JSON RPC

This also works out of the box with the JSON RPC layer:

      {
        "time": 1776160491,
        "host": "127.0.0.1",
        "service": "",
        "type": "host.comments",
        "data": {
          "host_data": "hello world, this is a comment"
        }
      },
      {
        "time": 1776072168,
        "host": "",
        "service": "",
        "type": "evasion.fileformat.syscall_inject.localpath",
        "data": {
          "full_path": "/Users/sjanusz/.msf4/local/met.exe"
        }
      },

Verification

List the steps needed to make sure this thing works

  • Start msfconsole
  • load msgrpc
  • Run RPC client using msfrpc
  • Verify calling rpc.call("db.notes", {}) works and returns the expected notes data in correct format

Comment thread lib/msf/core/rpc/v10/rpc_db.rb
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the db.notes RPC endpoint output so note data is returned as structured content (rather than an inspected string), aligning the RPC response with how notes are stored/used elsewhere in the framework.

Changes:

  • Return Mdm::Note#data directly from rpc_notes instead of n.data.inspect.

Comment on lines 1159 to 1161
note[:type ] = n.ntype.to_s
note[:data] = n.data.inspect
note[:data] = n.data
ret[:notes] << note
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpc_notes now returns n.data directly, which (1) does not implement the requested backward compatibility for legacy notes where data is a plain String (issue asks to convert those to a JSON-like object such as { "data": "..." }), and (2) can return non-JSON/MessagePack-friendly values (e.g., nested Symbols, Times, custom objects) that previously were safely stringified via inspect. Consider normalizing the outgoing value to JSON-safe primitives (deep-stringify keys and coerce unknown values), and wrapping non-Hash data in a predictable structure; also update the YARD docs above this method which still state 'data' [String].

Copilot uses AI. Check for mistakes.
@sjanusz-r7 sjanusz-r7 force-pushed the db-notes-rpc-return-notes-json-data branch from fe2ed7a to 6a6dffc Compare April 14, 2026 16:58
@sjanusz-r7 sjanusz-r7 force-pushed the db-notes-rpc-return-notes-json-data branch from 6a6dffc to 0446c0d Compare April 14, 2026 16:59
@adfoster-r7 adfoster-r7 requested a review from Copilot April 16, 2026 09:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines 1158 to +1160
note[:service] = n.service.name || n.service.port if n.service
note[:type ] = n.ntype.to_s
note[:data] = n.data.inspect
note[:data] = n.data
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the db.notes RPC response shape (data is no longer always a String). There are existing RPC v10 specs (e.g., for console/core/session), but none covering RPC_Db#rpc_notes; adding a spec that exercises rpc_notes with (1) Hash note data, (2) legacy String note data, and (3) nil/edge cases would help prevent regressions and validate the intended serialization behavior.

Copilot generated this review using guidance from organization custom instructions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second the idea of further rspec tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Update the db.notes RPC endpoint to return the note's data as a JSON

5 participants