Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to HyperSQL weak credentials tester #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions hsqldb/weak_credentials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# HyperSQL Weak Credentials Setup

1. On hsqldb_unsecured folder there is a Dockerfile that creates an instance with default HyperSQL default credentials

2. On hsqldb_secured folder there is a Dockerfile that creates an instance with a different password

3. UNSECURED: Run the docker build: `cd hsqldb_unsecured && docker build . -t hsqldb_unsecured && docker run -d -p 8080:9001 --name hsqldb_unsecured hsqldb_unsecured && cd ..`

4. Connect to it locally by using hsqldb.jar and sqltool.jar with command `java -cp hsqldb-2.7.2.jar:sqltool.jar org.hsqldb.cmdline.SqlTool --inlineRc=url=jdbc:hsqldb:hsql://localhost:8080/testdb,user=SA,password=`

5. SECURED: Run the docker build: `cd hsqldb_secured && docker build . -t hsqldb_secured && docker run -d -p 8081:9001 --name hsqldb_secured hsqldb_secured && cd ..`

6. Connect to it locally by using hsqldb.jar and sqltool.jar with command `java -cp hsqldb-2.7.2.jar:sqltool.jar org.hsqldb.cmdline.SqlTool --inlineRc=url=jdbc:hsqldb:hsql://localhost:8081/testdb,user=SA` and using password `securedpassword`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @GiuseppePorcu, thanks for your contribution!
Testbed is fine, however step 6 can be improved by providing a command equivalent to the one in step 5, along with an alternative to verify whether a password has effectively been set.

Suggested change
6. Connect to it locally by using hsqldb.jar and sqltool.jar with command `java -cp hsqldb-2.7.2.jar:sqltool.jar org.hsqldb.cmdline.SqlTool --inlineRc=url=jdbc:hsqldb:hsql://localhost:8081/testdb,user=SA` and using password `securedpassword`
6. Connect to it locally using `hsqldb.jar` and `sqltool.jar` as follows:
`java -cp hsqldb-2.7.2.jar:sqltool.jar org.hsqldb.cmdline.SqlTool --inlineRc=url=jdbc:hsqldb:hsql://localhost:8081/testdb,user=SA,password=`
The above command will not log in successfully with an empty password, as expected. To authenticate properly, remove the password parameter and enter the correct password `securedpassword` when prompted. The final working command is:
`echo -n securedpassword | java -cp hsqldb-2.7.2.jar:sqltool.jar org.hsqldb.cmdline.SqlTool --inlineRc=url=jdbc:hsqldb:hsql://localhost:8081/testdb,user=SA`


7. CLEAN-UP: Run the command `docker stop hsqldb_unsecured && docker rm hsqldb_unsecured && docker stop hsqldb_secured && docker rm hsqldb_secured`
Binary file added hsqldb/weak_credentials/hsqldb.jar
Binary file not shown.
28 changes: 28 additions & 0 deletions hsqldb/weak_credentials/hsqldb_secured/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM openjdk:11-jre-slim

# Install curl
RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/*

# Set environment variables
ENV HSQLDB_VERSION=2.7.2
ENV HSQLDB_HOME=/opt/hsqldb
ENV PATH="${HSQLDB_HOME}:${PATH}"

# Download and set up HSQLDB
RUN mkdir -p ${HSQLDB_HOME} \
&& curl -L -o ${HSQLDB_HOME}/hsqldb.jar https://repo1.maven.org/maven2/org/hsqldb/hsqldb/${HSQLDB_VERSION}/hsqldb-${HSQLDB_VERSION}.jar \
&& curl -L -o ${HSQLDB_HOME}/sqltool.jar https://repo1.maven.org/maven2/org/hsqldb/sqltool/${HSQLDB_VERSION}/sqltool-${HSQLDB_VERSION}.jar

# Expose HSQLDB port
EXPOSE 9001

# Run HSQLDB server, apply the initialization script, and stop the server
RUN java -cp ${HSQLDB_HOME}/hsqldb.jar org.hsqldb.server.Server \
--database.0 file:/opt/hsqldb/testdb --dbname.0 testdb & \
sleep 5 && \
java -cp "${HSQLDB_HOME}/hsqldb.jar:${HSQLDB_HOME}/sqltool.jar" org.hsqldb.cmdline.SqlTool \
--inlineRc=url=jdbc:hsqldb:hsql://localhost/testdb,user=SA,password= \
--sql "ALTER USER SA SET PASSWORD 'securedpassword';"

# Command to run HSQLDB server
CMD ["java", "-cp", "/opt/hsqldb/hsqldb.jar", "org.hsqldb.server.Server", "--database.0", "file:/opt/hsqldb/testdb", "--dbname.0", "testdb"]
19 changes: 19 additions & 0 deletions hsqldb/weak_credentials/hsqldb_unsecured/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM openjdk:11-jre-slim

# Install curl
RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/*

# Set environment variables
ENV HSQLDB_VERSION=2.7.2
ENV HSQLDB_HOME=/opt/hsqldb
ENV PATH="${HSQLDB_HOME}:${PATH}"

# Download and set up HSQLDB
RUN mkdir -p ${HSQLDB_HOME} \
&& curl -L -o ${HSQLDB_HOME}/hsqldb.jar https://repo1.maven.org/maven2/org/hsqldb/hsqldb/${HSQLDB_VERSION}/hsqldb-${HSQLDB_VERSION}.jar

# Expose HSQLDB port
EXPOSE 9001

# Command to run HSQLDB server
CMD ["java", "-cp", "/opt/hsqldb/hsqldb.jar", "org.hsqldb.server.Server", "--database.0", "file:/opt/hsqldb/testdb", "--dbname.0", "testdb"]
Binary file added hsqldb/weak_credentials/sqltool.jar
Binary file not shown.