Skip to content

Commit 7add94c

Browse files
authored
Fix apache E2E tests (#249)
* test * f * f * Fix apache * f * f * f * f * f * f
1 parent c799223 commit 7add94c

File tree

10 files changed

+38
-33
lines changed

10 files changed

+38
-33
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
go build -ldflags "-s -w" -buildmode=c-shared -o ../../build/aikido-request-processor.so
7373
ls -l ../../build
7474
75-
- name: Archive agent
75+
- name: Archive agent
7676
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
7777
if: always()
7878
with:
@@ -149,7 +149,7 @@ jobs:
149149
run: |
150150
cd ./build/modules
151151
mv aikido.so ${{ env.AIKIDO_ARTIFACT }}.so
152-
152+
153153
- name: Archive build artifacts
154154
uses: actions/upload-artifact@v4
155155
if: always()
@@ -245,7 +245,7 @@ jobs:
245245
if: matrix.os == 'ubuntu-22.04'
246246
run: |
247247
yum deplist ~/rpmbuild/RPMS/${{ env.ARCH }}/${{ env.AIKIDO_ARTIFACT_RELEASE }} | grep -E "GLIBC_2.32|GLIBC_2.34|GLIBCXX_3.4.29" && exit 1 || exit 0
248-
248+
249249
- name: Archive rpm package
250250
uses: actions/upload-artifact@v4
251251
with:
@@ -301,19 +301,19 @@ jobs:
301301
echo $AIKIDO_VERSION
302302
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
303303
echo "AIKIDO_RPM=aikido-php-firewall.${{ env.ARCH }}.rpm" >> $GITHUB_ENV
304-
echo "AIKIDO_ARTIFACT=aikido-php-firewall.${{ env.ARCH }}.deb" >> $GITHUB_ENV
305-
304+
echo "AIKIDO_ARTIFACT=aikido-php-firewall.${{ env.ARCH }}.deb" >> $GITHUB_ENV
305+
306306
- name: Build deb
307307
run: |
308308
alien --to-deb --scripts --keep-version ${{ env.AIKIDO_RPM }}/${{ env.AIKIDO_RPM }}
309309
mv aikido-php-firewall_${{ env.AIKIDO_VERSION }}-1_${{ env.DEB_ARCH }}.deb temp-${{ env.AIKIDO_ARTIFACT }}
310-
310+
311311
# Package contents into deb with gzip compression (because default zstd compression is not supported by older versions of dpkg)
312312
mkdir deb-temp
313313
dpkg-deb -R temp-${{ env.AIKIDO_ARTIFACT }} deb-temp/
314314
dpkg-deb -Zgzip -b deb-temp ${{ env.AIKIDO_ARTIFACT }}
315315
rm -rf deb-temp
316-
316+
317317
- name: Archive deb package
318318
uses: actions/upload-artifact@v4
319319
with:
@@ -367,11 +367,12 @@ jobs:
367367
mysqld -u root --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock &
368368
sleep 10
369369
mysql -u root -e "CREATE DATABASE IF NOT EXISTS db;"
370+
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd'; FLUSH PRIVILEGES;"
370371
371372
- name: Test MySQL connection with mysqli
372373
run: |
373374
php -r '
374-
$mysqli = new mysqli("localhost", "root", "", "db");
375+
$mysqli = new mysqli("localhost", "root", "pwd", "db");
375376
if ($mysqli->connect_error) {
376377
echo "MySQL connection failed: " . $mysqli->connect_error . "\n";
377378
exit(1);
@@ -396,7 +397,7 @@ jobs:
396397
echo $AIKIDO_VERSION
397398
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
398399
echo "AIKIDO_RPM=aikido-php-firewall.${{ env.ARCH }}.rpm" >> $GITHUB_ENV
399-
400+
400401
- name: Download artifacts
401402
uses: actions/download-artifact@v4
402403
with:
@@ -475,6 +476,7 @@ jobs:
475476
mysqld --user=root --datadir=/var/lib/mysql &
476477
sleep 10
477478
mysql -u root -e "CREATE DATABASE IF NOT EXISTS db;"
479+
mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pwd'); FLUSH PRIVILEGES;"
478480
479481
- name: Setup PHP
480482
uses: shivammathur/setup-php@27853eb8b46dc01c33bf9fef67d98df2683c3be2
@@ -486,7 +488,7 @@ jobs:
486488
- name: Test MySQL connection with mysqli
487489
run: |
488490
php -r '
489-
$mysqli = new mysqli("localhost", "root", "", "db");
491+
$mysqli = new mysqli("localhost", "root", "pwd", "db");
490492
if ($mysqli->connect_error) {
491493
echo "MySQL connection failed: " . $mysqli->connect_error . "\n";
492494
exit(1);
@@ -514,6 +516,8 @@ jobs:
514516
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure -f noninteractive tzdata
515517
apt-get install -y libapache2-mod-php${{ matrix.php_version }}
516518
a2enmod php${{ matrix.php_version }}
519+
apt-get install -y php${{ matrix.php_version }}-mysqli
520+
apt-get install -y php${{ matrix.php_version }}-pdo
517521
php -i
518522
519523
- name: Setup Python
@@ -542,4 +546,3 @@ jobs:
542546
if-no-files-found: ignore
543547
path: |
544548
${{ github.workspace }}/tests/cli/**/*.diff
545-
/var/log/mysql/error.log

lib/php-extension/Action.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ACTION_STATUS Action::executeThrow(json &event) {
66
int _code = event["code"].get<int>();
77
std::string _message = event["message"].get<std::string>();
88
zend_throw_exception(zend_exception_get_default(), _message.c_str(), _code);
9+
CallPhpFunctionWithOneParam("http_response_code", _code);
910
return BLOCK;
1011
}
1112

lib/request-processor/attack/attack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func GetThrowAction(message string, code int) string {
7979
}
8080

8181
func GetAttackDetectedAction(result utils.InterceptorResult) string {
82-
return GetThrowAction(BuildAttackDetectedMessage(result), -1)
82+
return GetThrowAction(BuildAttackDetectedMessage(result), 500)
8383
}
8484

8585
func ReportAttackDetected(res *utils.InterceptorResult) string {

tests/server/test_sql_injection_mysqli_obj_multi_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$mysqli = new mysqli("localhost", "root", "", "db");
6+
$mysqli = new mysqli("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if ($mysqli->connect_error) {

tests/server/test_sql_injection_mysqli_obj_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$mysqli = new mysqli("localhost", "root", "", "db");
6+
$mysqli = new mysqli("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if ($mysqli->connect_error) {

tests/server/test_sql_injection_mysqli_obj_real_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$mysqli = new mysqli("localhost", "root", "", "db");
6+
$mysqli = new mysqli("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if ($mysqli->connect_error) {

tests/server/test_sql_injection_mysqli_procedure_multi_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$conn = mysqli_connect("localhost", "root", "", "db");
6+
$conn = mysqli_connect("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if (!$conn) {

tests/server/test_sql_injection_mysqli_procedure_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$conn = mysqli_connect("localhost", "root", "", "db");
6+
$conn = mysqli_connect("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if (!$conn) {

tests/server/test_sql_injection_mysqli_procedure_real_query/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\aikido\set_user("12345", "Tudor");
44

55
// Connect to MySQL (adjust credentials as needed)
6-
$conn = mysqli_connect("localhost", "root", "", "db");
6+
$conn = mysqli_connect("127.0.0.1", "root", "pwd", "db");
77

88
// Check connection
99
if (!$conn) {

tools/server_tests/apache/main.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,18 @@
7878
Options Indexes FollowSymLinks
7979
AllowOverride All
8080
Require all granted
81-
81+
8282
RewriteEngine On
8383
RewriteCond %{{REQUEST_FILENAME}} !-f
8484
RewriteCond %{{REQUEST_FILENAME}} !-d
8585
RewriteRule ^(.*)$ index.php [L]
86-
86+
8787
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
8888
</Directory>
8989
9090
ErrorLog {log_dir}/error_{name}.log
9191
CustomLog {log_dir}/access_{name}.log combined
92+
9293
</VirtualHost>
9394
"""
9495

@@ -137,7 +138,7 @@ def toggle_config_line(file_path, line_to_check, comment_ch, enable=False):
137138
if not os.path.exists(file_path):
138139
print(f"File '{file_path}' does not exist.")
139140
return
140-
141+
141142
with open(file_path, 'r') as file:
142143
lines = file.readlines()
143144

@@ -185,9 +186,9 @@ def select_apache_user():
185186
if u in usernames:
186187
apache_user = u
187188
break
188-
189+
189190
assert apache_user is not None
190-
191+
191192
print("Selected apache user: ", apache_user)
192193

193194

@@ -220,7 +221,7 @@ def apache_create_config_file(test_name, test_dir, server_port, env):
220221
optional_conf = apache_include_conf,
221222
error_log = apache_error_log
222223
)
223-
224+
224225
apache_config_file = os.path.join(test_dir, f"{test_name}.conf")
225226
with open(apache_config_file, "w") as f:
226227
f.write(apache_config)
@@ -239,13 +240,13 @@ def add_user_group_access(full_path, user, group):
239240
current_path = os.sep.join(path_parts[:i])
240241
if current_path: # Avoid empty strings for the root "/"
241242
# print(f"Setting permissions for {current_path}")
242-
243+
243244
# Change ownership of the directory
244245
subprocess.run(['chown', f'{user}:{group}', current_path], check=True)
245246

246247
# Ensure the execute permission (search permission) on directories
247248
subprocess.run(['chmod', '775', current_path], check=True)
248-
249+
249250
print(f"Successfully added access to full path '{full_path}' for user '{user}' and group '{group}'.")
250251
except subprocess.CalledProcessError as e:
251252
print(f"Failed to modify permissions: {e}")
@@ -259,28 +260,28 @@ def apache_mod_php_init(tests_dir):
259260
subprocess.run(['mkdir', '-p', apache_log_folder], check=True)
260261
subprocess.run(['chown', f'{apache_user}:{apache_user}', apache_log_folder], check=True)
261262
subprocess.run(['chmod', '755', apache_log_folder], check=True)
262-
263-
263+
264+
264265
toggle_config_line(apache_conf_proxy_module_file, "LoadModule proxy_fcgi_module", "#")
265266
toggle_config_line(apache_conf_proxy_h2_module_file, "LoadModule proxy_http2_module", "#")
266-
267+
267268
toggle_config_line(apache_conf_mpm_worker_file, "LoadModule mpm_worker_module", "#")
268269
toggle_config_line(apache_conf_mpm_event_file, "LoadModule mpm_event_module", "#")
269270
toggle_config_line(apache_conf_mpm_prefork_file, "LoadModule mpm_prefork_module", "#", enable=True)
270-
271+
271272
global prev_owning_user, prev_owning_group
272273
prev_owning_user, prev_owning_group = get_user_and_group(tests_dir)
273274
print(f"Got previous owning user:group -> {prev_owning_user}:{prev_owning_group}")
274-
275+
275276

276277
def apache_mod_php_process_test(test_data):
277278
test_dir = test_data["test_dir"]
278279
server_port = test_data["server_port"]
279280
test_data["apache_config"] = apache_create_config_file(test_data["test_name"], test_dir, server_port, test_data["env"])
280-
281+
281282
global apache_user
282283
add_user_group_access(os.path.join(test_dir, "index.php"), apache_user, apache_user)
283-
284+
284285
# append_if_not_exists(apache_conf_global_file, f"Listen {server_port}\n")
285286
return test_data
286287

0 commit comments

Comments
 (0)