---
# System prepended metadata

title: L4. Configuration Services for Pentest. Answers

---

# L4. Configuration Services for Pentest. Answers

## Exercise 1 – FTP*
1. Start the "ftp" service with python and "pyftplib" module
>https://github.com/giampaolo/pyftpdlib
:::spoiler
```bash=
apt update
apt install python3-pip
```
```python=
pip install pyftpdlib
python -m pyftpdlib -p 21 -d ftp
```
:::

---

## Exercise 2 – Samba*
1. Start the “smbd” service with "impacket"
>https://github.com/SecureAuthCorp/impacket
:::spoiler
```bash=
cd impacket
smbserver share .
or
smbserver.py -smb2support share /home/user/folder/
```
:::

---

## Exercise 3 – Apache2*
1. Install the Apache2 service
2. Checking status of Web Server
3. Setting Up Virtual Hosts
:::spoiler
```bash=
apt-get update
apt-get install apache2
mkdir -p /var/www/example.com/public_html
mkdir -p /var/www/test.com/public_html
chown -R $USER:$USER /var/www/example.com/public_html
chown -R $USER:$USER /var/www/test.com/public_html
chmod -R 755 /var/www
nano /var/www/example.com/public_html/index.html
```
```htmlmixed=
<html>
  <head>
    <title>Welcome to Example.com!</title>
  </head>
  <body>
    <h1>Success!  The example.com virtual host is working!</h1>
  </body>
</html>
```
```bash=
cp /var/www/example.com/public_html/index.html /var/www/test.com/public_html/index.html
nano /var/www/test.com/public_html/index.html
```
```htmlmixed=
<html>
  <head>
    <title>Welcome to Test.com!</title>
  </head>
  <body> <h1>Success!  The test.com virtual host is working!</h1>
  </body>
</html>
```
```bash=
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.com.conf
nano /etc/apache2/sites-available/example.com.conf
```
```htmlmixed=
<VirtualHost *:80>
 # The ServerName directive sets the request scheme, hostname and port that
 # the server uses to identify itself. This is used when creating
 # redirection URLs. In the context of virtual hosts, the ServerName
 # specifies what hostname must appear in the request's Host: header to
 # match this virtual host. For the default virtual host (this file) this
 # value is not decisive as it is used as a last resort host regardless.
 # However, you must set it for any further virtual host explicitly.
 #ServerName www.example.com

   ServerAdmin webmaster@example.com
   ServerName example.com
   ServerAlias www.example.com
   DocumentRoot /var/www/html/example.com/public_html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 # error, crit, alert, emerg.
 # It is also possible to configure the loglevel for particular
 # modules, e.g.
 #LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
 # enabled or disabled at a global level, it is possible to
 # include a line for only one particular virtual host. For example the
 # following line enables the CGI configuration for this host only
 # after it has been globally disabled with "a2disconf".
 #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
```
```bash=
nano /etc/apache2/sites-available/test.com.conf
```
```htmlmixed=
<VirtualHost *:80>
 # The ServerName directive sets the request scheme, hostname and port that
 # the server uses to identify itself. This is used when creating
 # redirection URLs. In the context of virtual hosts, the ServerName
 # specifies what hostname must appear in the request's Host: header to
 # match this virtual host. For the default virtual host (this file) this
 # value is not decisive as it is used as a last resort host regardless.
 # However, you must set it for any further virtual host explicitly.
 #ServerName www.example.com

    ServerAdmin webmaster@ostechnix2.lan
    ServerName ostechnix2.lan
    ServerAlias www.ostechnix2.lan
    DocumentRoot /var/www/html/ostechnix2.lan/public_html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 # error, crit, alert, emerg.
 # It is also possible to configure the loglevel for particular
 # modules, e.g.
 #LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
 # enabled or disabled at a global level, it is possible to
 # include a line for only one particular virtual host. For example the
 # following line enables the CGI configuration for this host only
 # after it has been globally disabled with "a2disconf".
 #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
```
```bash=
a2dissite 000-default.conf
a2ensite ostechnix1.lan.conf
a2ensite ostechnix2.lan.conf
service apache2 restart
nano /etc/hosts
```
>192.168.225.22   ostechnix1.lan
>192.168.225.22   ostechnix2.lan
:::

---

## Exercise 4 – tiny-Web-services*
1. Start web-services with python
:::spoiler
```python=
python -m SimpleHTTPServer 8000
python3 -m http.server 8000
```
:::
3. Start web-services with ruby
:::spoiler
```ruby=
ruby -rwebrick -e "WEBrick::HTTPServer.new(:Port => 80, :DocumentRoot => Dir.pwd).start"
ruby -run -e httpd . -p 8000
```
:::
3. Start web-services with php
:::spoiler
```php=
php -S $ip:80
php -S 0.0.0.0:8000
```
:::

