Como executar um binário do Windows/DOS no Linux (Continuação do Post anterior sobre compilar binário de Windows, dentro do Linux)

Continuação do post:

https://firebitsbr.wordpress.com/2015/08/31/cross-compiling-de-arquivo-em-linguagem-c-compilando-em-linux-executando-em-windows/

Para testar seu binário de Windows, no próprio Linux, com se fosse um Windows…rss:) (Wine tá bugado na VM de testes).

[test@localhost sampler]$ wine cmd
fixme:winediag:start_process Wine Staging 1.7.49 is a testing version containing experimental patches.
fixme:winediag:start_process Please report bugs at http://bugs.wine-staging.com (instead of winehq.org).
Microsoft Windows 5.2.3790 (1.7.49)

Z:\home\test\sampler>fixme:ole:RemUnknown_QueryInterface No interface for iid {00000019-0000-0000-c000-000000000046}
Z:\home\test\sampler>dir
Volume in drive Z has no label.
Volume Serial Number is 0000-0000

Directory of Z:\home\test\sampler

8/31/2015 1:49 PM <DIR> .
8/31/2015 1:45 PM <DIR> ..
8/31/2015 1:15 PM 103 HelloWorld.c
8/31/2015 1:27 PM 67,385 HelloWorld.exe
8/31/2015 10:19 AM 717 HelloWorldCPL.c
8/31/2015 1:35 PM 67,385 HelloWorldCPL01
8/31/2015 1:15 PM 103 HelloWorldCPL01.c
8/31/2015 1:35 PM 67,385 HelloWorldCPL01.cpl
6 files 203,078 bytes
2 directories 95,160,651,776 bytes free
Z:\home\test\sampler>HelloWorldHelloWorld.exe
Sampler Test!

Não adiantar usar comandos de Linux, agora você estará no Windows

Z:\home\test\sampler>clear
Can’t recognize ‘clear’ as an internal or external command, or batch script.

Z:\home\test\sampler>exit
[test@localhost sampler]$ clear

Espero ter ajudado!

@firebitsbr

Cross-Compiling de Arquivo em Linguagem C (Compilando em Linux, Executando em Windows)

Estava fazendo um PoC (Proof of Concept) e precisava criar um sampler para testes, mas não queria criar uma VM com Windows, instalar GCC ou VS, só para criar um PE32 (Executável para Windows 32bits, arquitetura x86), então fui pesquisar sobre MinGW.

O problema é que a máquina de testes do Lab está usando um Fedora 22 e quando você procura no terminal por “MinGW”, não aparece nada rapidamente.

Buscando nesta wiki, achei o MinGW versão Fedora, que está com outra nomeclatura no package:

https://fedoraproject.org/wiki/MinGW/Tutorial (x86_64-w64-mingw32-gcc)

[root@localhost sampler]# x86_64-w64-mingw32-gcc HelloWorld.c -o HelloWorld

HelloWorld

[root@localhost sampler]# file HelloWorld
HelloWorld: PE32+ executable (console) x86-64, for MS Windows

Agora sim!:)

Espero ter ajudado alguém!:)

@firebitsbr

 

Running nmap via golang

Hi. Another post about golang ;)

I was developing a small source code in golang to automate the use of nmap , based on these examples:

https://github.com/mmcgrana/gobyexample/blob/master/examples/spawning-processes/spawning-processes.go
https://gobyexample.com/spawning-processes

But it was not succeed until I developed it and it worked :

[root@localhost golang]# vim go-nmap.go

// Mauro Risonho de Paula Assumpção aka firebits
// mauro.risonho@gmail.com
// example os/exec nmap
// 24.07.2015 15:04:23
// fedora 22 x86-64
// go version go1.4.2 linux/amd64
// go build

package main

import “syscall”
import “os”
import “os/exec”

func main() {

// For our example we’ll exec `ls`. Go requires an
// absolute path to the binary we want to execute, so
// we’ll use `exec.LookPath` to find it (probably
// `/bin/nmap`).

binary, lookErr := exec.LookPath(“/usr/bin/nmap”)
if lookErr != nil {
panic(lookErr)
}

// `Exec` requires arguments in slice form (as
// apposed to one big string). We’ll give `ls` a few
// common arguments. Note that the first argument should
// be the program name.
// args := []string{“nmap”, “-A”, “-O”, “127.0.0.1”}
args := []string{“nmap”, “-A”, “127.0.0.1”}

// `Exec` also needs a set of [environment variables](environment-variables)
// to use. Here we just provide our current
// environment.
env := os.Environ()

// Here’s the actual `syscall.Exec` call. If this call is
// successful, the execution of our process will end
// here and be replaced by the `/bin/ls -a -l -h`
// process. If there is an error we’ll get a return
// value.
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}
}

I installed a vm with Fedora 22 x86_64 and CUPS server and did a spot scanning in localhost 127.0.0.1

[root@localhost golang]# go build go-nmap.go
[root@localhost golang]# ./go-nmap

Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-24 15:06 BRT
Nmap scan report for localhost.localdomain (127.0.0.1)
Host is up (0.00015s latency).
Not shown: 999 closed ports
PORT STATE SERVICE VERSION
631/tcp open ipp CUPS 2.0
| http-methods: Potentially risky methods: PUT
|_See http://nmap.org/nsedoc/scripts/http-methods.html
| http-robots.txt: 1 disallowed entry
|_/
|_http-title: Home – CUPS 2.0.3
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.7 – 3.15
Network Distance: 0 hops

OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.06 seconds

So it works!

@firebitsbr

April 2nd, 2015 – OpenVAS-8 released: Charts, Quality of Detection and PostgreSQL-Support –

http://www.openvas.org/news_archive.html

Following the annual release cycle, the new generation of OpenVAS [1] has been released. The new version of the open framework for vulnerability scanning and management, OpenVAS-8, introduces a comprehensively extended and improved feature set. Advances and improvements were achieved in virtually all areas.

Highlights of this new release are the chart module for a variety of graphical representation, the Quality of Detection (QoD) concept and the optional support of PostgreSQL as database backend. Major advances were also achieved for the access control management: more roles, group admins and super-admin to name just a few. Notable as well is the introduction of the optional multi-scanner support via the new protocol OSP (OpenVAS Scanner Protocol) for which a growing number of servers is expected for the future. Last but not least, the OpenVAS Scanner now requires less ressources and uses redis[2] for the inter-process communication.

All in all OpenVAS-8 ships 28 new and improved features, accompanied with countless smaller changes. The systematic improvements and reliable release of one major update every twelve months once again underlines the position of OpenVAS as the most advanced Open Source solution for vulnerability management. The new version can be downloaded free and is available as Free Software under the GNU GPL license.

The company Greenbone Networks [3] develops and uses OpenVAS as a base for its appliance product family for vulnerability scanning and management. Together with the company SecPod [4] and the growing community, new vulnerability tests and feature improvements are developed on a daily basis. The German Federal Office for Information Security (BSI) [5] supports and utilizes OpenVAS, together with many other federal agencies, as part of their IT security framework.

Vulnerability Management:

Access Control:
The access control features were comprehensively extended.
Roles can now be dynamically configured.
New default roles “Monitor”, “Guest” and “Super Admin”.
New Permissions “Super” that allows for example to define an administrator for a group.
Results are now an explicit part of the scan management.
The new section “Results” under menu “Scan Management” offers an object management for all of the scan results in the database a user has permission for. In other words, searching and filtering for results is now possible independent of a scan report.
Solution Type:
NVTs are now associated with a solution type like for example “VendorFix”. This allows to group or identify NVTs or results where for example a simple solution exists or no solution is currently available.
The Feed content is updated over time to add a solution type for all of the NVTs. At the time of writing, 3.6% of the NVTs own a Solution Type.
Quality of Detection (QoD):
The QoD is a value between 0% and 100% describing the reliability of the executed vulnerability detection or product detection.
One of the main reasons to introduce this concept was to handle the challenge of potential vulnerabilities properly. The goal was to keep such in the results database but only visible on demand.
While the QoD range allows to express the quality pretty refined, in fact most of the test routines use a standard methodology. Therefore the QoD Types were introduced of which each is associated with a QoD value.
The Feed content is updated over time to add a QoD for all NVTs. Any NVT not explicitly assigned will apply 75% and therefore visible by default in order to not change the default behavior compared to OpenVAS-7. However, meanwhile any NVTs formerly requiring the “paranoid” setting in the scan configuration is now reporting always but stay invisible in the database until the user decides to view results with a lower quality of detection.
At the time of writing, 2.7% of the NVTs own a QoD Type.
New SecInfo object type “CERT-Bund” introduced: These are advisories published by the German federal CERT.
Vulnerability Scanning:

Credentials:
The public key of SSH credentials is not required anymore because it is extracted from the private key.
Credentials for ESXi target systems can now be configured directly with the Target object instead of in the Scan Configuration object.
When a task is requested to stop, the scanner will now be advised to switch immediately into the final phase of scanning. With OpenVAS-7 the scanner immediately stopped activity and did not return so far collected host details. With OpenVAS-8 this is now transferred to the the database.
Dropped support for pausing of tasks entirely (was removed from GUI before, now removed from OMP level).
OpenVAS Scanning Protocol (OSP):
This new protocol allows to control a vulnerability scanner. The main elements are to set parameters, start a scan and retrieve results. OSP is designed in the same way as OMP, therefore it is a non-permanent request-response connection based on XML.
It is possible to configure and control OSP-compliant Scanner via the user interface.
OpenVAS-8 offers some pilot OSP scanners in order to provide examples for this technology. Users and developers are encouraged to wrap more vulnerability scanner with OSP and provide feedback on missing features in the OSP protocol.
The OpenVAS Scanner itself is still OTP-based and the integration with OpenVAS Manager works like before with the slight difference that it is now possible to define more than one OpenVAS Scanner to be controlled by OpenVAS Manager.
This new concepts introduces various changes in the user interface but defaults are set to keep the same behavior as in OpenVAS-7 if user decides not to deal with OSP. In other words: OSP is entirely optional.
Graphical User Interface:

Dynamic charts are introduced, using the Javascript library “d3”. The first chart types (bar, donut, bubbles, line) are used for the SecInfo section in order to demonstrate some of the capabilities.
The chart objects allow to download the data as CSV table or SVG graphics. Also, a HTML table can be opened and some of the charts are interactive.
The underlying data aggregation technology is generically integrated into the protocol OMP. This allows to add more charts during the lifecycle of the OpenVAS release because no API changes are required.
For the SecInfo Management, a first dashboard is integrated which assembles four of the charts and can be configured individually.
The charting feature is entirely optional: Without enabling Javascript support in the browser no core functionality is lost. Also, the chart view can be collapsed so that only the traditional table view is shown.
Bulk actions are introduced. For example this allows to remove or download many objects within a single action.
The powerfilter was simplified to carry only the essential filter elements. The standard ones are displayed below and of course it is possible to apply any of them in the text entry field.
Timezones:
The configuration of timezones was changed so that now there is offered a drop down list of available timezones instead of a entry field for specifying the timezone in text form.
Users are now allowed to have multiple simultaneous sessions, as long as the sessions are on different browsers. Up-to OpenVAS-7, a second session always invalidated the previous one regardless of which browser is used.
For any web interface page, the duration of the backend operation will be shown at the bottom.
The filenames for downloads can now be configured via “My Settings”.
New wizard for modifying a task.
Protocols:

OMP now in version 6.0
The new OSP for controlling arbitrary scanners is at version 1.0.
The OTP protocol was further reduced. It is not recommended to use it to communicate with the OpenVAS Scanner because it will eventually be dropped in favor of OSP. For the time being OMP should be used to control a OpenVAS Scanner.
Architecture:

redis (mandatory):
The OpenVAS Scanner now uses a redis backend to share the knwoledge base among the scanning processes.
PostgreSQL (optional):
OpenVAS Manager now allows to use PostgreSQL as an alternative for the file-based SQLite. Everything should work, but this new database backend has seen little testing so far.
The OpenVAS development team is prepared to fix any issues promptly as it is desired to make this database eventually the new default backend.
openvas-smb (optional):
The new module “openvas-smb” is used for WMI support. This is the former externally maintained wmi client library. Since it was actually not maintained anymore, the module was cut down to the essentials and furnished with a “cmake” build environment.
OSP (optional):
For the new OSP, a base module “OSPd” written in Python is made available. The actual wrappers for vulnerability scanners are collected as “osp-scanners” and the name of the modules is prefixed with “OSPd-“. “OSPd” is a mandatory requirement for each OSP scanner module.
All sample OSP scanners are writtin in Python. Currently the C-library API only supports OSP client functionality, not server functionality.
The memory consumption of the OpenVAS Scanner was reduced by about 50%.
References:

[1] OpenVAS: http://www.openvas.org/
[2] redis: http://redis.io/
[3] Greenbone: http://www.greenbone.net/
[4] SecPod: http://www.secpod.com/
[5] BSI: https://www.bsi.bund.de//

@firebitsbr

HowTo- Instalando OpenVAS8 + Debian 8 + Redis

Olá.

Segue mais um HowTo- Instalando OpenVAS8 + Debian 8 + Redis by @firebitsbr ;)

No caso é só fazer download de um debian 8 x64 bits – netinstall e depois criar um shell script (*.sh) após a instalação total do Debian (maquina fisica ou virtual) e executá-lo:

chmod -x 755 openvas8_debian.sh

Abaixo, o openvas8_debian.sh (completo):

#!/bin/bash
#OpenVAS 8 Installer Debian 8
#Mauro Risonho de Paula Assumpção aka firebits
#download do debian 8 x64 bits
#http://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-8.0.0-amd64-netinst.iso

# Passo 1 – pacotes requeridos para instalação
apt-get install -y build-essential devscripts dpatch libassuan-dev libglib2.0-dev libgpgme11-dev libpcre3-dev libpth-dev libwrap0-dev libgmp-dev libgmp3-dev libgpgme11-dev libpcre3-dev libpth-dev quilt cmake pkg-config libssh-dev libglib2.0-dev libpcap-dev libgpgme11-dev uuid-dev bison libksba-dev doxygen sqlfairy xmltoman sqlite3 libsqlite3-dev wamerican redis-server libhiredis-dev libsnmp-dev libmicrohttpd-dev libxml2-dev libxslt1-dev xsltproc libssh2-1-dev libldap2-dev autoconf nmap libgnutls-dev libpopt-dev heimdal-dev heimdal-multidev libpopt-dev mingw32 texlive-full rpm alien nsis

# Passo 2 – Copiar arquivo de config para backup, setar unixsocket e subir o database redis
cp /etc/redis/redis.conf /etc/redis/redis.orig
echo “unixsocket /tmp/redis.sock” >> /etc/redis/redis.conf
service redis-server restart

# Passo 3 – Criar pasta openvas8 e download dos sources codes
mkdir openvas8
cd openvas8/

wget –no-check-certificate https://wald.intevation.org/frs/download.php/2015/openvas-libraries-8.0.1.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2016/openvas-scanner-5.0.1.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2017/openvas-manager-6.0.1.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2018/greenbone-security-assistant-6.0.1.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/1987/openvas-cli-1.4.0.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/1975/openvas-smb-1.0.1.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/1999/ospd-1.0.0.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2005/ospd-ancor-1.0.0.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2003/ospd-ovaldi-1.0.0.tar.gz
wget –no-check-certificate https://wald.intevation.org/frs/download.php/2004/ospd-w3af-1.0.0.tar.gz

# Passo 4 – Extrair em lote os sources codes compactados
find | grep “.tar.gz$” | xargs -i tar zxvfp ‘{}’

# Passo 5 – Compilação de cada pacote de source codes – OBS: Sempre nesta ordem ou haverá quebra de compilação.
cd openvas-smb*
mkdir build
cd build/
cmake ..
make
make doc-full
make install
cd ../../

cd openvas-libraries-*
mkdir build
cd build
cmake ..
make
make doc-full
make install
cd ../../

cd openvas-scanner-*
mkdir build
cd build/
cmake ..
make
make doc-full
make install
cd ../../

cd openvas-manager-*
mkdir build
cd build/
cmake ..
make
make doc-full
make install
cd ../../

cd openvas-cli-*
mkdir build
cd build/
cmake ..
make
make doc-full
make install
cd ../../

cd greenbone-security-assistant-*
mkdir build
cd build/
cmake ..
make
make doc-full
make install
cd ../../

# Recarregar as bibliotecas
ldconfig

# Criar CA para o client
openvas-mkcert
openvas-mkcert-client -n -i

# Criar usuario admin / anote a senha hash a ser criada, pois sera usada posteriormente
openvasmd –create-user=admin –role=Admin && openvasmd –user=admin –new-password=1

# Criar shell script para atualização de plugins, scap e informações do cert.
echo ‘#!/bin/bash’ > /usr/local/sbin/openvas-update
echo ‘/usr/local/sbin/openvas-nvt-sync’ >> /usr/local/sbin/openvas-update
echo ‘/usr/local/sbin/openvas-scapdata-sync’ >> /usr/local/sbin/openvas-update
echo ‘/usr/local/sbin/openvas-certdata-sync’ >> /usr/local/sbin/openvas-update
chmod +x /usr/local/sbin/openvas-update

# Criar shell script para inicialização dos daemons. OBS: Sempre nesta ordem, senão não carrega corretamente.
echo ‘#!/bin/bash’ > /usr/local/sbin/openvas-start
echo ‘/usr/local/sbin/openvasmd –rebuild’ >> /usr/local/sbin/openvas-start
echo ‘/usr/local/sbin/openvasmd’ >> /usr/local/sbin/openvas-start
echo ‘/usr/local/sbin/openvassd’ >> /usr/local/sbin/openvas-start
echo ‘/usr/local/sbin/gsad’ >> /usr/local/sbin/openvas-start
chmod +x /usr/local/sbin/openvas-start

# Criar shell script para matar dos daemons, caso seja necessario reiniciar todos os daemons corretamente . OBS: Sempre nesta ordem, senão não carrega corretamente.
echo ‘#!/bin/bash’ > /usr/local/sbin/openvas-kill
echo “ps aux | egrep \”(openvas.d|gsad)\” | awk ‘{print \$2}’ | xargs -i kill ‘{}'” >> /usr/local/sbin/openvas-kill
chmod +x /usr/local/sbin/openvas-kill

# Criar shell script para inicializar os daemons logo após a inicialização do SO, mediante rc.local . OBS: Sempre nesta ordem, senão não carrega corretamente.
rclocal=`cat /etc/rc.local | grep -v “exit 0” | grep -v “openvas”`
echo “$rclocal” > /etc/rc.local
echo “date >> /var/log/openvas_init” >> /etc/rc.local
echo “echo ‘openvas init started’ >> /var/log/openvas_init” >> /etc/rc.local
echo “/usr/local/sbin/openvas-kill >> /var/log/openvas_init || /bin/true” >> /etc/rc.local
echo “/usr/local/sbin/openvas-start >> /var/log/openvas_init || /bin/true” >> /etc/rc.local
echo “echo ‘openvas init finished’ >> /var/log/openvas_init” >> /etc/rc.local
echo “exit 0” >> /etc/rc.local

# Scripts acima, ja no formato de shellscript sendo validados e carregados
/usr/local/sbin/openvas-kill
/usr/local/sbin/openvas-update
/usr/local/sbin/openvas-start

# Verificando se a instalação foi feita corretamente para OpenVAS8
wget https://svn.wald.intevation.org/svn/openvas/trunk/tools/openvas-check-setup –no-check-certificate
chmod 0755 openvas-check-setup
./openvas-check-setup –v8 –server

Por enquanto, só testei em Debian 8 x64 bits, mas acho que pode funcionar em Ubuntu e derivados e com um pouco de adaptação em outros linux (Redhat, Fedora, Slackware e outros).

Ultimamente está bem corrido, meu dia-a-dia, mas poste nos comentários do meu blog, qualquer dúvida, se houver e com um pouco de tempo, eu retorno.

Espero ter ajudado!;)

@firebitsbr