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

Feat(#24) initial pre-commit hooks #34

Closed
wants to merge 9 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/compile_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'c/**'
- '.github/**'
pull_request:


permissions:
contents: read
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: executable-C-MacOS
path: target/*
path: target/*
build-linux:
name: Linux(X86-64)
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compile_golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: executable-Go-Windows
path: target/*
path: target/*
33 changes: 33 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pre-commit check

# Controls when the workflow will run
on:
pull_request:
branches: [main]
workflow_dispatch:

permissions:
contents: read
jobs:
pre-commit:
name: Pre-commit check
runs-on: ubuntu-latest
steps:
- name: Checkout git repository
uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install missing tools
run: >
brew install gcc llvm uncrustify cppcheck include-what-you-use clang-format cpplint && \
brew install --cask oclint
- name: Pre-commit checks
uses: pre-commit/[email protected]
- name: pre-commit-ci-lite
uses: pre-commit-ci/[email protected]
if: always()
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
autofix_prs: false # managed in the action step
autoupdate_branch: ""
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
autoupdate_schedule: weekly
skip: []
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
# exclude: ^(src/test/resources/yourkey.txt|src/test/resources/secondkey.txt)
- id: trailing-whitespace
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.81.0
hooks:
- id: terraform_fmt
- id: terraform_tflint
args:
- "--args=--only=terraform_deprecated_interpolation"
- "--args=--only=terraform_deprecated_index"
- "--args=--only=terraform_unused_declarations"
- "--args=--only=terraform_comment_syntax"
- "--args=--only=terraform_documented_outputs"
- "--args=--only=terraform_documented_variables"
- "--args=--only=terraform_typed_variables"
- "--args=--only=terraform_module_pinned_source"
- "--args=--only=terraform_naming_convention"
- "--args=--only=terraform_required_version"
- "--args=--only=terraform_required_providers"
- "--args=--only=terraform_standard_module_structure"
- "--args=--only=terraform_workspace_remote"
- id: terraform_docs
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.5.0
hooks:
- id: commitlint
stages: [commit-msg]
- repo: https://github.com/pocc/pre-commit-hooks #https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [--style=Google]
- id: clang-tidy
- id: uncrustify
- id: cppcheck
- id: cpplint
- id: include-what-you-use
1 change: 0 additions & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
For further reference, please consider the following sections:

<TBD>

2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Thank you for submitting a pull request to the WrongSecrets-binaries repository!
Thank you for submitting a pull request to the WrongSecrets-binaries repository!
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# wrongsecrets-binaries

[![Compile C](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_c.yml/badge.svg)](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_c.yml)
[![ Compile CPlus](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_cplus.yml/badge.svg)](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_cplus.yml)
[![ Compile CPlus](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_cplus.yml/badge.svg)](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_cplus.yml)
[![Compile GoLang](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_golang.yml/badge.svg)](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_golang.yml)
[![Compile Rust](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_rust.yml/badge.svg)](https://github.com/OWASP/wrongsecrets-binaries/actions/workflows/compile_rust.yml)

This is a supportive repository for [OWASP WrongSecrets](https://github.com/OWASP/wrongsecrets).
Here we create our binaries which are included in the official project.
Want to add a challenge related to secrets hiding in binary? Open a ticket at [WrongSecrets issues](https://github.com/OWASP/wrongsecrets/issues).
Want to add a challenge related to secrets hiding in binary? Open a ticket at [WrongSecrets issues](https://github.com/OWASP/wrongsecrets/issues).
Want to fix something you found in one of the binaries: open a ticket or a PR here.

## Special thanks
Expand Down
87 changes: 39 additions & 48 deletions c/main.c
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
// Copyright 2023 Jeroen Willemsen and OWASP Wrongsecrets team

#include <stdio.h>
#include <string.h>

const char *secret()
{
return "This is a hardcoded secret in C";
// clang-format off
const char *secret() {
return "This is a hardcoded secret in C";
}
// clang-format on

const char *secret2()
{
static char harder[31] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'h', 'a', 'r', 'd', 'c', 'o', 'd', 'e', 'd', ' ', 's', 'e', 'c', 'r', 'e', 't', ' ', 'i', 'n', ' ', 'C'};
return harder;
const char *secret2() {
static char harder[31] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
'a', ' ', 'h', 'a', 'r', 'd', 'c', 'o',
'd', 'e', 'd', ' ', 's', 'e', 'c', 'r',
'e', 't', ' ', 'i', 'n', ' ', 'C'};
return harder;
}

int spoil()
{
printf("%s\n", secret());
return 0;
int spoil() {
printf("%s\n", secret());
return 0;
}

int compare(char *guess)
{
int result = strcmp(secret(), guess);
int result2 = strcmp(secret2(), guess);
if (result == 0)
{
printf("This is correct! Congrats!\n");
}
else
{
printf("This is incorrect. Try again\n");
}
return result;
int compare(char *guess) {
int result = strcmp(secret(), guess);
int result2 = strcmp(secret2(), guess);
if (result == 0 && result2 == 0) {
printf("This is correct! Congrats!\n");
} else {
printf("This is incorrect. Try again\n");
}
return result;
}

int execute(char *command)
{
if (strcmp("spoil", command) == 0)
{
return spoil();
}
return compare(command);
int execute(char *command) {
if (strcmp("spoil", command) == 0) {
return spoil();
}
return compare(command);
}

int main(int argc, char *argv[])
{
if (argc == 2)
{
execute(argv[1]);
}

else if (argc > 2)
{
printf("Too many arguments supplied.\n");
}
else
{
printf("Welcome to the wrongsecrets C binary which hides a secret.\n");
printf("Use args spoil or a string to guess the password.\n");
}
}
int main(int argc, char *argv[]) {
if (argc == 2) {
execute(argv[1]);
} else if (argc > 2) {
printf("Too many arguments supplied.\n");
} else {
printf("Welcome to the wrongsecrets C binary which hides a secret.\n");
printf("Use args spoil or a string to guess the password.\n");
}
}
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
rustflags = ["-Clinker=rust-lld"]
rustflags = ["-Clinker=rust-lld"]
96 changes: 37 additions & 59 deletions cplus/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,50 @@

using namespace std;

class Secretcontainer
{ // The class
private: // Access specifier
string secret; // Attribute (string variable)
public:
void setSecret(string secretarg)
{
secret = secretarg;
}
string getSecret()
{
return secret;
}
class Secretcontainer { // The class
private: // Access specifier
string secret; // Attribute (string variable)
public:
void setSecret(string secretarg) { secret = secretarg; }
string getSecret() { return secret; }
};

Secretcontainer secret()
{
Secretcontainer container;
container.setSecret("Another secret in C++");
return container;
Secretcontainer secret() {
Secretcontainer container;
container.setSecret("Another secret in C++");
return container;
}

char *secret2()
{
static char harder[22] = {'A', 'n', 'o', 't', 'h', 'e', 'r', ' ', 's', 'e', 'c', 'r', 'e', 't', ' ', 'i', 'n', ' ', 'C', ' ', '+', '+'};
return harder;
char *secret2() {
static char harder[22] = {'A', 'n', 'o', 't', 'h', 'e', 'r', ' ',
's', 'e', 'c', 'r', 'e', 't', ' ', 'i',
'n', ' ', 'C', ' ', '+', '+'};
return harder;
}

void spoil()
{
cout << secret().getSecret();
}
void spoil() { cout << secret().getSecret(); }

int execute(string command)
{
string spoil("spoil");
if (spoil.compare(command) == 0)
{
cout << secret().getSecret() + '\n';
return 0;
}
else if (secret().getSecret().compare(command) == 0)
{
cout << "This is correct! Congrats!\n";
return 0;
}
else
{
cout << "This is incorrect. Try again\n";
return 1;
}
int execute(string command) {
string spoil("spoil");
if (spoil.compare(command) == 0) {
cout << secret().getSecret() + '\n';
return 0;
} else if (secret().getSecret().compare(command) == 0) {
cout << "This is correct! Congrats!\n";
return 0;
} else {
cout << "This is incorrect. Try again\n";
return 1;
}
}

int main(int argc, char *argv[])
{
if (argc == 2)
{
execute(argv[1]);
}
else if (argc > 2)
{
cout << "Too many arguments supplied.\n";
}
else
{
cout << "Welcome to the wrongsecrets C++ binary which hides a secret.\n";
cout << "Use args spoil or a string to guess the password.\n";
}
int main(int argc, char *argv[]) {
if (argc == 2) {
execute(argv[1]);
} else if (argc > 2) {
cout << "Too many arguments supplied.\n";
} else {
cout << "Welcome to the wrongsecrets C++ binary which hides a secret.\n";
cout << "Use args spoil or a string to guess the password.\n";
}
}
Loading
Loading