-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 196b8c5
Showing
11 changed files
with
560 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
############################################################################### | ||
## OCSINVENTORY-NG | ||
## Copyleft Silvan Raijer 2022 | ||
## Web : http://www.ocsinventory-ng.org | ||
## | ||
## This code is open source and may be copied and modified as long as the source | ||
## code is always made freely available. | ||
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt | ||
################################################################################ | ||
|
||
package Apache::Ocsinventory::Plugins::Listeningports::Map; | ||
|
||
use strict; | ||
|
||
use Apache::Ocsinventory::Map; | ||
$DATA_MAP{listeningports} = { | ||
mask => 0, | ||
multi => 1, | ||
auto => 1, | ||
delOnReplace => 1, | ||
sortBy => 'PROCESS', | ||
writeDiff => 0, | ||
cache => 0, | ||
fields => { | ||
PROCESS => {}, | ||
PORT => {}, | ||
} | ||
}; | ||
1; |
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 @@ | ||
PerlModule Apache::Ocsinventory::Plugins::Listeningports::Map |
Large diffs are not rendered by default.
Oops, something went wrong.
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,4 @@ | ||
# OCS Inventory Plugin - Listening Ports | ||
Gather Listening ports from NetTCPConnection | ||
|
||
Currently Windows are supported. |
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 @@ | ||
[CmdletBinding()] | ||
Param ( | ||
) | ||
|
||
### | ||
# Functions | ||
### | ||
function GenerateXML { | ||
param ( | ||
[Parameter(Mandatory=$True)][string]$port, | ||
[Parameter(Mandatory=$True)][string]$process | ||
) | ||
|
||
$port = $($($port.subString(0, [System.Math]::Min(255, $port.Length)))) | ||
$process = $($($process.subString(0, [System.Math]::Min(255, $process.Length)))) | ||
|
||
$generateXML += "<LISTENINGPORTS>`n" | ||
$generateXML += "<PORT>"+ $port +"</PORT>`n" | ||
$generateXML += "<PROCESS>"+ $process +"</PROCESS>`n" | ||
$generateXML += "</LISTENINGPORTS>`n" | ||
return $generateXML | ||
} | ||
|
||
### | ||
# Core | ||
### | ||
Try { | ||
$xml = '' | ||
write-verbose "[INFO] Gathering listening ports" | ||
$listening_ports = Get-NetTCPConnection -State Listen | Select-Object -Property LocalPort,@{'Name' = 'ProcessName';'Expression'={(Get-Process -Id $_.OwningProcess).Name}} -Unique | Sort-Object -Property LocalPort | ||
foreach ($setting in $listening_ports) { | ||
if ($setting.LocalPort -and $setting.ProcessName) { | ||
$resultXML += $(GenerateXML $($setting.LocalPort) $($setting.ProcessName)) | ||
} | ||
} | ||
|
||
} | ||
Catch { | ||
write-verbose $Error[0] | ||
} | ||
|
||
write-verbose "[INFO] Sending report..." | ||
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' | ||
[Console]::WriteLine($resultXML) | ||
write-verbose "[INFO] Done sending report" | ||
write-verbose "[INFO] Exiting" |
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,69 @@ | ||
<?php | ||
############################################################################### | ||
## OCSINVENTORY-NG | ||
## Copyleft Silvan Raijer 2022 | ||
## Web : http://www.ocsinventory-ng.org | ||
## | ||
## This code is open source and may be copied and modified as long as the source | ||
## code is always made freely available. | ||
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt | ||
################################################################################ | ||
|
||
|
||
/** | ||
* This file is used to build a table refering to the plugin and define its | ||
* default columns as well as SQL request. | ||
*/ | ||
|
||
if (AJAX) { | ||
parse_str($protectedPost['ocs']['0'], $params); | ||
$protectedPost += $params; | ||
ob_start(); | ||
$ajax = true; | ||
} else { | ||
$ajax = false; | ||
} | ||
|
||
|
||
// print a title for the table | ||
print_item_header($l->g(79700)); | ||
|
||
if (!isset($protectedPost['SHOW'])) { | ||
$protectedPost['SHOW'] = 'NOSHOW'; | ||
} | ||
|
||
// form details and tab options | ||
$form_name = "listeningports"; | ||
$table_name = $form_name; | ||
$tab_options = $protectedPost; | ||
$tab_options['form_name'] = $form_name; | ||
$tab_options['table_name'] = $table_name; | ||
|
||
|
||
echo open_form($form_name); | ||
$list_fields = array( | ||
'Process' => 'PROCESS', | ||
'Port' => 'PORT' | ||
); | ||
// columns to include at any time and default columns | ||
$list_col_cant_del = $list_fields; | ||
$default_fields = $list_fields; | ||
|
||
// select columns for table display | ||
$sql = prepare_sql_tab($list_fields); | ||
$sql['SQL'] .= "FROM $table_name WHERE (hardware_id = $systemid)"; | ||
|
||
array_push($sql['ARG'], $systemid); | ||
$tab_options['ARG_SQL'] = $sql['ARG']; | ||
$tab_options['ARG_SQL_COUNT'] = $systemid; | ||
ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del); | ||
|
||
echo close_form(); | ||
|
||
|
||
if ($ajax) { | ||
ob_end_clean(); | ||
tab_req($list_fields, $default_fields, $list_col_cant_del, $sql['SQL'], $tab_options); | ||
ob_start(); | ||
} | ||
?> |
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<hookstore> | ||
<hook type="lang"> | ||
<value>en_GB</value> | ||
<value>fr_FR</value> | ||
</hook> | ||
<hook type="cdentry"> | ||
<identifier>cd_listeningports</identifier> | ||
<translation>79700</translation> | ||
<category>other</category> | ||
<available>listeningports</available> | ||
</hook> | ||
</hookstore> |
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,13 @@ | ||
{ | ||
"displayName" : "Listening Ports", | ||
"author" : ["Antoine ROBIN"], | ||
"contributor" : ["Aaron Johnson"], | ||
"supportedAgent" : ["Windows"], | ||
"version" : "1.0", | ||
"licence" : "GPLv2", | ||
"description" : | ||
{ | ||
"en" : "Gather Listening ports", | ||
"fr" : "Liste les ports en écoute" | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
/** | ||
* The following functions are used by the extension engine to generate a new table | ||
* for the plugin / destroy it on removal. | ||
*/ | ||
|
||
|
||
/** | ||
* This function is called on installation and is used to | ||
* create database schema for the plugin | ||
*/ | ||
function extension_install_listeningports() | ||
{ | ||
$commonObject = new ExtensionCommon; | ||
|
||
$commonObject -> sqlQuery( | ||
"CREATE TABLE IF NOT EXISTS `listeningports` ( | ||
`ID` INTEGER NOT NULL AUTO_INCREMENT, | ||
`HARDWARE_ID` INTEGER NOT NULL, | ||
`PORT` VARCHAR(255) DEFAULT NULL, | ||
`PROCESS` VARCHAR(255) DEFAULT NULL, | ||
PRIMARY KEY (ID,HARDWARE_ID)) ENGINE=INNODB;" | ||
); | ||
} | ||
|
||
/** | ||
* This function is called on removal and is used to | ||
* destroy database schema for the plugin | ||
*/ | ||
function extension_delete_listeningports() | ||
{ | ||
$commonObject = new ExtensionCommon; | ||
$commonObject -> sqlQuery("DROP TABLE IF EXISTS `listeningports`"); | ||
} | ||
|
||
/** | ||
* This function is called on plugin upgrade | ||
*/ | ||
function extension_upgrade_listeningports() | ||
{ | ||
|
||
} | ||
|
||
?> |
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 @@ | ||
79700 Listening ports |
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 @@ | ||
79700 Port en écoute |