Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
8d5a20f5
Commit
8d5a20f5
authored
Feb 23, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move tasks generation to configuration
parent
66c8dabe
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
155 additions
and
42 deletions
+155
-42
configuration.yml
service/configuration.yml
+22
-10
CTFApplication.java
service/src/main/java/CTFApplication.java
+28
-20
ApplicationConfiguration.java
service/src/main/java/core/ApplicationConfiguration.java
+19
-11
CryptoTaskConfig.java
service/src/main/java/helpers/CryptoTaskConfig.java
+43
-0
WebTaskConfig.java
service/src/main/java/helpers/WebTaskConfig.java
+43
-0
TaskResource.java
service/src/main/java/resources/TaskResource.java
+0
-1
No files found.
service/configuration.yml
View file @
8d5a20f5
...
@@ -4,16 +4,6 @@ dbName: db
...
@@ -4,16 +4,6 @@ dbName: db
flagHashMethod
:
"
MD5"
flagHashMethod
:
"
MD5"
testsTemporary
:
-
value
:
"
a"
asdf
:
"
ff"
-
value
:
"
a"
asdf
:
"
ff"
-
value
:
"
a"
asdf
:
"
ff"
-
value
:
"
a"
asdf
:
"
ff"
teams
:
teams
:
-
name
:
"
misiaczki"
-
name
:
"
misiaczki"
description
:
"
misiaczki
opis"
description
:
"
misiaczki
opis"
...
@@ -51,3 +41,25 @@ teams:
...
@@ -51,3 +41,25 @@ teams:
-
name
:
"
rosiu3"
-
name
:
"
rosiu3"
password
:
"
188ed9df2dac8e10f5c5fd2e02383765"
#rosiu321 md5
password
:
"
188ed9df2dac8e10f5c5fd2e02383765"
#rosiu321 md5
email
:
"
rosiu@gmail.com"
email
:
"
rosiu@gmail.com"
cryptoTasks
:
-
name
:
"
Szyfro1"
text
:
"
Odszyfruj1"
flag
:
"
asdf"
level
:
1
-
name
:
"
Szyfro2"
text
:
"
Odszyfruj2"
flag
:
"
sdfg"
level
:
2
webTasks
:
-
name
:
"
SQL
Injection"
url
:
"
http://google.pl"
flag
:
"
fgh"
level
:
3
-
name
:
"
Inna
dziura"
url
:
"
http://wikipedia.pl"
flag
:
"
hjk"
level
:
4
service/src/main/java/CTFApplication.java
View file @
8d5a20f5
...
@@ -6,6 +6,8 @@ import com.google.inject.Injector;
...
@@ -6,6 +6,8 @@ import com.google.inject.Injector;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClient
;
import
core.ApplicationConfiguration
;
import
core.ApplicationConfiguration
;
import
core.TaskType
;
import
core.TaskType
;
import
helpers.CryptoTaskConfig
;
import
helpers.WebTaskConfig
;
import
io.dropwizard.Application
;
import
io.dropwizard.Application
;
import
io.dropwizard.assets.AssetsBundle
;
import
io.dropwizard.assets.AssetsBundle
;
import
io.dropwizard.auth.*
;
import
io.dropwizard.auth.*
;
...
@@ -26,13 +28,9 @@ import repositories.SolutionsRepository;
...
@@ -26,13 +28,9 @@ import repositories.SolutionsRepository;
import
repositories.TasksRepository
;
import
repositories.TasksRepository
;
import
repositories.TeamsRepository
;
import
repositories.TeamsRepository
;
import
repositories.UsersRepository
;
import
repositories.UsersRepository
;
import
resources.ProxyResource
;
import
resources.*
;
import
resources.SolutionsResource
;
import
resources.TasksResource
;
import
resources.TeamsResource
;
import
resources.TaskResource
;
import
java.util.
UUID
;
import
java.util.
List
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
/**
/**
...
@@ -49,8 +47,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -49,8 +47,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
private
Injector
injector
;
private
Injector
injector
;
@Override
@Override
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
{
{
bootstrap
.
addBundle
(
new
AssetsBundle
(
"/assets"
,
"/page"
,
"index.html"
));
bootstrap
.
addBundle
(
new
AssetsBundle
(
"/assets"
,
"/page"
,
"index.html"
));
Stream
.
of
(
"org.webjars.npm"
,
"org.webjars.bower"
)
Stream
.
of
(
"org.webjars.npm"
,
"org.webjars.bower"
)
.
map
(
WebJarBundle:
:
new
)
.
map
(
WebJarBundle:
:
new
)
...
@@ -73,17 +70,28 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -73,17 +70,28 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
});
});
}
}
private
void
initializeTasks
()
{
private
void
initializeTasks
(
ApplicationConfiguration
applicationConfiguration
)
{
int
numberOfNewTasks
=
20
;
List
<
CryptoTaskConfig
>
cryptoTasks
=
applicationConfiguration
.
getCryptoTasks
();
List
<
WebTaskConfig
>
webTasks
=
applicationConfiguration
.
getWebTasks
();
tasksRepository
.
clean
();
tasksRepository
.
clean
();
for
(
int
i
=
0
;
i
<
numberOfNewTasks
;
i
++)
{
Task
task
=
new
Task
(
String
.
valueOf
(
UUID
.
randomUUID
()),
i
,
cryptoTasks
.
forEach
(
cryptoTaskConfig
->
tasksRepository
.
add
(
new
Task
(
i
%
2
==
0
?
TaskType
.
CRYPTO
:
TaskType
.
WEB
,
cryptoTaskConfig
.
getName
(),
Flag
.
newRandomFlag
(),
cryptoTaskConfig
.
getLevel
(),
i
%
2
==
0
?
new
TaskCryptoContent
(
"crypto text"
)
:
new
TaskWebContent
(
"http://google.com"
)
TaskType
.
CRYPTO
,
);
new
Flag
(
cryptoTaskConfig
.
getFlag
()),
tasksRepository
.
add
(
task
);
new
TaskCryptoContent
(
cryptoTaskConfig
.
getText
())
}
)));
webTasks
.
forEach
(
webTaskConfig
->
tasksRepository
.
add
(
new
Task
(
webTaskConfig
.
getName
(),
webTaskConfig
.
getLevel
(),
TaskType
.
WEB
,
new
Flag
(
webTaskConfig
.
getFlag
()),
new
TaskWebContent
(
webTaskConfig
.
getUrl
())
)));
}
}
private
void
initializeSolutions
()
{
private
void
initializeSolutions
()
{
...
@@ -117,7 +125,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -117,7 +125,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
initializeTeams
(
applicationConfiguration
);
initializeTeams
(
applicationConfiguration
);
initializeTasks
();
initializeTasks
(
applicationConfiguration
);
initializeSolutions
();
initializeSolutions
();
registerResources
(
environment
);
registerResources
(
environment
);
registerAuthFeatures
(
environment
);
registerAuthFeatures
(
environment
);
...
@@ -135,7 +143,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -135,7 +143,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
@Override
@Override
public
com
.
google
.
common
.
base
.
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
{
public
com
.
google
.
common
.
base
.
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
{
User
user
=
usersRepository
.
authenticateUser
(
credentials
);
User
user
=
usersRepository
.
authenticateUser
(
credentials
);
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
return
Optional
.
of
(
user
);
return
Optional
.
of
(
user
);
}
}
return
Optional
.
absent
();
return
Optional
.
absent
();
...
...
service/src/main/java/core/ApplicationConfiguration.java
View file @
8d5a20f5
package
core
;
package
core
;
import
helpers.CryptoTaskConfig
;
import
helpers.WebTaskConfig
;
import
io.dropwizard.Configuration
;
import
io.dropwizard.Configuration
;
import
objects.Team
;
import
objects.Team
;
...
@@ -12,12 +14,26 @@ public class ApplicationConfiguration extends Configuration {
...
@@ -12,12 +14,26 @@ public class ApplicationConfiguration extends Configuration {
private
String
dbHost
;
private
String
dbHost
;
private
int
dbPort
;
private
int
dbPort
;
private
String
dbName
;
private
String
dbName
;
private
String
flagHashMethod
;
private
String
flagHashMethod
;
private
List
<
Team
>
teams
;
private
List
<
Team
>
teams
;
private
List
<
CryptoTaskConfig
>
cryptoTasks
;
private
List
<
WebTaskConfig
>
webTasks
;
public
List
<
CryptoTaskConfig
>
getCryptoTasks
()
{
return
cryptoTasks
;
}
private
List
<
Test
>
testsTemporary
;
public
void
setCryptoTasks
(
List
<
CryptoTaskConfig
>
cryptoTasks
)
{
this
.
cryptoTasks
=
cryptoTasks
;
}
public
List
<
WebTaskConfig
>
getWebTasks
()
{
return
webTasks
;
}
public
void
setWebTasks
(
List
<
WebTaskConfig
>
webTasks
)
{
this
.
webTasks
=
webTasks
;
}
public
String
getFlagHashMethod
()
{
public
String
getFlagHashMethod
()
{
return
flagHashMethod
;
return
flagHashMethod
;
...
@@ -31,14 +47,6 @@ public class ApplicationConfiguration extends Configuration {
...
@@ -31,14 +47,6 @@ public class ApplicationConfiguration extends Configuration {
this
.
teams
=
teams
;
this
.
teams
=
teams
;
}
}
public
List
<
Test
>
getTestsTemporary
()
{
return
testsTemporary
;
}
public
void
setTestsTemporary
(
List
<
Test
>
testsTemporary
)
{
this
.
testsTemporary
=
testsTemporary
;
}
public
void
setFlagHashMethod
(
String
flagHashMethod
)
{
public
void
setFlagHashMethod
(
String
flagHashMethod
)
{
this
.
flagHashMethod
=
flagHashMethod
;
this
.
flagHashMethod
=
flagHashMethod
;
}
}
...
...
service/src/main/java/helpers/CryptoTaskConfig.java
0 → 100644
View file @
8d5a20f5
package
helpers
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
class
CryptoTaskConfig
{
private
String
name
;
private
int
level
;
private
String
text
;
private
String
flag
;
public
String
getName
()
{
return
name
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
String
getFlag
()
{
return
flag
;
}
public
void
setFlag
(
String
flag
)
{
this
.
flag
=
flag
;
}
}
service/src/main/java/helpers/WebTaskConfig.java
0 → 100644
View file @
8d5a20f5
package
helpers
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
class
WebTaskConfig
{
private
String
name
;
private
String
url
;
private
int
level
;
private
String
flag
;
public
String
getName
()
{
return
name
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getFlag
()
{
return
flag
;
}
public
void
setFlag
(
String
flag
)
{
this
.
flag
=
flag
;
}
}
service/src/main/java/resources/TaskResource.java
View file @
8d5a20f5
...
@@ -14,7 +14,6 @@ import repositories.TasksRepository;
...
@@ -14,7 +14,6 @@ import repositories.TasksRepository;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment