-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1abe643
commit fce5f66
Showing
9 changed files
with
405 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ Commands: | |
spider | ||
user-agent | ||
wordlist | ||
xml | ||
``` | ||
|
||
Open the `ronin-web` Ruby REPL: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# frozen_string_literal: true | ||
# | ||
# ronin-web - A collection of useful web helper methods and commands. | ||
# | ||
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com) | ||
# | ||
# ronin-web is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# ronin-web is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with ronin-web. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
require 'ronin/web/cli/command' | ||
require 'ronin/support/network/http' | ||
|
||
require 'nokogiri' | ||
|
||
module Ronin | ||
module Web | ||
class CLI | ||
module Commands | ||
# | ||
# Performs XPath queries on a URL or XML file. | ||
# | ||
# ## Usage | ||
# | ||
# ronin-web xml [options] {URL | FILE} [XPATH] | ||
# | ||
# ## Options | ||
# | ||
# -X, --xpath XPATH XPath query | ||
# -t, --text Prints the inner-text | ||
# -F, --first Only print the first match | ||
# -h, --help Print help information | ||
# | ||
# ## Arguments | ||
# | ||
# URL | FILE The URL or FILE to search | ||
# XPATH The XPath query | ||
# | ||
# @since 2.0.0 | ||
# | ||
class Xml < Command | ||
|
||
usage '[options] {URL | FILE} [XPATH]' | ||
|
||
option :xpath, short: '-X', | ||
value: { | ||
type: String, | ||
usage: 'XPATH' | ||
}, | ||
desc: 'XPath query' do |xpath| | ||
@query = xpath | ||
end | ||
|
||
option :first, short: '-F', | ||
desc: 'Only print the first match' | ||
|
||
option :text, short: '-t', | ||
desc: 'Prints the elements inner text' | ||
|
||
argument :source, required: true, | ||
usage: 'URL | FILE', | ||
desc: 'The URL or FILE to search' | ||
|
||
argument :query, required: false, | ||
usage: 'XPATH', | ||
desc: 'The XPath query' | ||
|
||
description 'Performs XPath queries on a URL or HTML file' | ||
|
||
man_page 'ronin-web-xml.1' | ||
|
||
# The XPath expression. | ||
# | ||
# @return [String, nil] | ||
attr_reader :query | ||
|
||
# | ||
# Runs the `ronin-web xml` command. | ||
# | ||
# @param [String] source | ||
# The `URL` or `FILE` argument. | ||
# | ||
# @param [String, nil] query | ||
# The optional XPath argument. | ||
# | ||
def run(source,query=@query) | ||
unless query | ||
print_error "must specify --xpath or an XPath argument" | ||
exit(-1) | ||
end | ||
|
||
doc = parse(read(source)) | ||
nodes = if options[:first] then doc.at(query) | ||
else doc.search(query) | ||
end | ||
|
||
if options[:text] | ||
puts nodes.inner_text | ||
else | ||
puts nodes | ||
end | ||
end | ||
|
||
# | ||
# Reads a URI or file. | ||
# | ||
# @param [String] source | ||
# The URI or file path. | ||
# | ||
# @return [File, String] | ||
# The contents of the URI or file. | ||
# | ||
def read(source) | ||
if source.start_with?('https://') || | ||
source.start_with?('http://') | ||
Support::Network::HTTP.get_body(source) | ||
else | ||
File.new(source) | ||
end | ||
end | ||
|
||
# | ||
# Parses the HTML source code. | ||
# | ||
# @param [String] html | ||
# The raw unparsed XML. | ||
# | ||
# @return [Nokogiri::XML::Document] | ||
# The parsed XML document. | ||
# | ||
def parse(html) | ||
Nokogiri::XML(html) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ Performs XPath/CSS-path queries on a URL or HTML file. | |
`-C`, `--css-path` *CSS-path* | ||
: The CSS-path query to perform. | ||
|
||
`-F`, `--first` | ||
: Only print the first match. | ||
|
||
`-t`, `--text` | ||
: Prints the inner-text of the matching elements. | ||
|
||
|
@@ -61,13 +64,13 @@ Performs XPath/CSS-path queries on a URL or HTML file. | |
`-u`, `--urls` | ||
: Dumps all URLs in the page. | ||
|
||
`-F`, `--first` | ||
: Only print the first match. | ||
|
||
`-h`, `--help` | ||
: Print help information. | ||
|
||
## AUTHOR | ||
|
||
Postmodern <[email protected]> | ||
|
||
## SEE ALSO | ||
|
||
[ronin-web-xml](ronin-web-xml.1.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ronin-web-xml 1 "2022-01-01" Ronin "User Manuals" | ||
|
||
## NAME | ||
|
||
ronin-web-xml - Performs XPath queries on a URL or XML file | ||
|
||
## SYNOPSIS | ||
|
||
`ronin-web xml` [*options*] {*URL* \| *FILE*} [*XPATH*] | ||
|
||
## DESCRIPTION | ||
|
||
Performs XPath queries on a URL or HTML file. | ||
|
||
## ARGUMENTS | ||
|
||
*URL* | ||
: The `http://` or `https://` URL to fetch and parse. | ||
|
||
*FILE* | ||
: The local XML file to parse. | ||
|
||
*XPATH* | ||
: The XPath query expression. | ||
|
||
## OPTIONS | ||
|
||
`-X`, `--xpath` *XPATH* | ||
: The XPath query to perform. | ||
|
||
`-F`, `--first` | ||
: Only print the first match. | ||
|
||
`-t`, `--text` | ||
: Prints the inner-text of the matching elements. | ||
|
||
`-h`, `--help` | ||
: Print help information. | ||
|
||
## AUTHOR | ||
|
||
Postmodern <[email protected]> | ||
|
||
## SEE ALSO | ||
|
||
[ronin-web-html](ronin-web-html.1.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ Postmodern <[email protected]> | |
|
||
## SEE ALSO | ||
|
||
[ronin-web-diff](ronin-web-diff.1.md) [ronin-web-html](ronin-web-html.1.md) [ronin-web-server](ronin-web-server.1.md) [ronin-web-spider](ronin-web-spider.1.md) [ronin-web-proxy](ronin-web-proxy.1.md) | ||
[ronin-web-diff](ronin-web-diff.1.md) [ronin-web-html](ronin-web-html.1.md) [ronin-web-server](ronin-web-server.1.md) [ronin-web-spider](ronin-web-spider.1.md) [ronin-web-proxy](ronin-web-proxy.1.md) [ronin-web-xml](ronin-web-xml.1.md) |
Oops, something went wrong.